# The entry chapter of Tkinter Tutorial
# entry used to enter Single-line text
' 1. The first entry program '
From Tkinter Import *
root = Tk ()
Entry (root,text = ' Input your text here '). Pack ()
Root.mainloop ()
# The above code is to create a entry object, and on the entry display ' Input your text here ', run this code, and do not see the text display, which can be different from lable and button, Entry Text property can not set entry
"2. Set the initial value in the entry and use Textvariable to bind the variable to the entry '"
From Tkinter Import *
root = Tk ()
E = Stringvar ()
Entry = Entry (root,textvariable = e)
E.set (' Input your text here ')
Entry.pack ()
Root.mainloop ()
# The above example binds the variable e to entry and then sets the value of E to ' input your text here ', and the initial value of the program is set.
"3. Set to read-only entry.
Another useful property of entry, 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 ()
# actually entry's property values can be used for normal/active/disabled, ' readonly ' and disabled
' 4. Set as password input box
#将Entry作为一个密码输入框来使用, the content value entered by the user is not displayed and is replaced with a specific symbol. Working with attributes
Show to specify.
'''
From Tkinter Import *
root = Tk ()
E = Stringvar ()
Entry = Entry (root,textvariable = e)
E.set (' Input your text here ')
Entry.pack ()
# Use * To display the input, if you like can be changed to other characters
entry[' show ' = ' * '
# Use *#$ to display the input text content separately
for mask in [' * ', ' # ', ' $ ']:
E = Stringvar ()
Entry = Entry (root,textvariable = e)
E.set (' password ')
Entry.pack ()
Entry[' show '] = Mask
Root.mainloop ()
"5. Verify that the input content meets the requirements.
Use validate to verify what is entered
Use the Validate method to restrict what you enter
This is an example of a problem where the ValidateText callback function cannot be invoked
‘ '''
From Tkinter Import *
root = Tk ()
E = Stringvar ()
def validatetext (contents):
Print contents
Return Contents.isalnum ()
Root.mainloop ()
'''
The documentation describes the events that are accepted using validate, using Validatecommand to determine whether the input is legal, but
How to pass in parameters. No instructions were found.
'''
# There are other attributes fg/bg/relief/width/height/justify/state using the same method as the button, no longer an example.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.