1. First entry procedure
From tkinter Import *root = Tk () Entry (Root). Pack () Root.mainloop ()
2. Set the initial value in entry, use Textvariable to bind the variable to entry
From tkinter Import *root = Tk () e = Stringvar () entry = entry (root,textvariable = e) e.set (' Input your text here ') Entry.pack () Root.mainloop ()
In the previous article, I used textvariable to change the text value in Buttun.
3. Set as read-only entry.
Another more useful property of entry, which is set to read-only, does not allow the user to change its value. Set the state property to ' ReadOnly '
From tkinter Import *root = Tk () e = Stringvar () entry = entry (root,textvariable = e) e.set (' Input your text here ') Entry.pack () entry[' state '] = ' readonly ' Root.mainloop ()
The Entry property value can be used for normal/active/disabled, ' ReadOnly ' is similar to disabled, except that disabled will be the component grayed out
4. Set As Password entry box
From tkinter Import *root = Tk () e = Stringvar () entry = entry (root,textvariable = e) e.set (' Input your text here ') Entry.pack () #使用 * To display input content, if preferred can be changed to another character entry[' show ' = ' * ' #分别使用 *#$ display the input text content for the mask in [' * ', ' # ', ' $ ']: e = stringvar () Entry = Entry (root,textvariable = e) e.set (' password ') entry.pack () entry[' show '] = Maskroot.mainloop ()
Python GUI----Entry