Placeholder in Tkinter
Last Updated :
24 Jan, 2021
Prerequisite:
Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python.
What is a placeholder and how can it be implemented using tkinter:
In programming, a placeholder may be a character, word, or string of characters that briefly takes the place of the final data. For instance, an applied scientist might recognize that she desires a precise range of values or variables, however does not however recognize what to input.
The Placeholder attribute is used to give hint that tells what input is expected by input field, or we can say it will give the short hint that is displayed within the input field before the user enters a value.
In Tkinter there is no in-built method or property for placeholder but it can still be executed using the modules’ inbuilt functions.
Approach:
- Import module
- Create Normal Tkinter Window
- Add Entry box
Syntax:
Entry(Object Name, **attr)
- Add placeholder, here it is done using insert() and then the same is bonded to the box
Syntax:
insert(index)
Program:
Python3
from tkinter import *
root = Tk()
root.geometry( '400x400' )
def click( * args):
playlist_url.delete( 0 , 'end' )
def leave( * args):
playlist_url.delete( 0 , 'end' )
playlist_url.insert( 0 , 'Enter Text:- ' )
root.focus()
playlist_url = Entry(root, width = 60 )
playlist_url.insert( 0 , 'Enter Text:- ' )
playlist_url.pack(pady = 10 )
playlist_url.bind( "<Button-1>" , click)
playlist_url.bind( "<Leave>" , leave)
root.mainloop()
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...