Tkinter tutorial entry

Source: Internet
Author: User
Tags tkinter tutorial
# Tkinter tutorial entry
# Entry is used to input a single line of text.
'''1. The first entry program '''
From tkinter import *
Root = TK ()
Entry (root, text = 'input your text here '). Pack ()
Root. mainloop ()
# The above Code aims to create an entry object and display 'input your text here 'on the entry. Run this code and no text is displayed, different from lable and button, the text attribute of entry cannot be set.

''' 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 ()

# In the preceding example, bind the variable e to the entry and set the value of E to 'input your text here '. The initial value is set when the program runs.

''' 3. Set to read-only entry.
Another useful attribute of entry, which is set to read-only and cannot be changed by the user.
Set the state attribute 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 ()

# In fact, the value of the entry attribute can also be normal/active/disabled, and 'readonly' is the same as disabled.

'''4. set as the password input box
# Use the entry as a password input box, that is, it does not display the content value entered by the user, instead of a specific symbol. Usage attributes
Show.
'''
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 content. If you like it, you can change it to another character.
Entry ['show '] = '*'
# Use * # $ to display the input text content
For mask in ['*', '#', '$']:
E = stringvar ()
Entry = entry (root, textvariable = E)
E. Set ('Password ')
Entry. Pack ()
Entry ['show'] = mask

Root. mainloop ()

''' 5. Verify that the entered content meets the requirements.
Use validate to verify the input content
Use the validate method to restrict input content
This is a problematic example. The validatetext callback function cannot be called.
''''
From tkinter import *
Root = TK ()
E = stringvar ()
Def validatetext (contents ):
Print Contents
Return contents. isalnum ()

Entry = entry (root, validate = 'key', textvariable = E, validatecommand = validatetext)
Entry. Pack ()

Root. mainloop ()
'''
Events that are accepted using validate are described in the document, and validatecommand is used to determine whether the input content is legal,
How do I pass in parameters? No corresponding description found
'''
# The usage of FG/BG/relief/width/height/justify/State is the same as that of button.

# Author: jcodeer
# Blog: jcodeer.cublog.cn
# Email: jcodeer@126.com

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.