Python Learning Tkinter notes (4)

Source: Internet
Author: User

This is mainly to learn how to do the input and output box, such as the production of password interface.

Here is a simple input box for making:

From tkinter Import *root = Tk () E = Entry (root) #输入框e. Pack (padx=20,pady=20) e.delete (0,end)    #把窗口从0到最后清空e. Insert (0, " Default text ")  # Place the default text typeface at 0 mainloop ()

A slightly more complicated box

From tkinter Import *root = Tk () Label (root,text= "artwork:"). Grid (row=0,column=0) #grid中关系着元素的网格布局第0行第0个位置Label (root,text= ""). Grid (row=1,column=0) #布局第1行第0个位置e1 =entry (root) e2=entry (root) E1.grid (row=0,column=1,padx=10,pady=5) #布局在 (0, 1) position E2.grid (row=1,column=1,padx=10,pady=5) #布局在 (the) Position def Show ():    print ("Work:%s"%e1.get ()) #通过调用Entry的get () The function can get the input string    print ("%s"%e2.get ())    Button (root,text= "Get Information", width=10,command=show). Grid (row=3,column=0 , sticky=w,padx=10,pady=5) #width关系着按键长度, command is a function call after pressing the key, sticky for W the module is placed on the left button (root,text= "Exit", width=10, command=root.quit). Grid (row=3,column=1,sticky=e,padx=10,pady=5) #root. Grid is the function that exits the window, sticky to E the module is placed Mainloop ()

If it is the account password, how to make the password with * to indicate it?

From tkinter Import *root = Tk () label (root,text= "Account:"). Grid (row=0,column=0) label (root,text= "Password:"). Grid (Row=1,column =0) V1 = stringvar () v2 = Stringvar () e1=entry (ROOT,TEXTVARIABLE=V1) e2=entry (root,textvariable=v2,show= "*") #用 * Show Input # Show is a representation of the input characters, such as can be *, but can also be other characters, such as ¥$ and so on E1.grid (row=0,column=1,padx=10,pady=5) E2.grid (row=1,column=1,padx= 10,PADY=5) def show ():    print ("Account:%s"%e1.get ()) #Entry. Get () to get the input string    print ("Password:%s"%e2.get ())    E1.delete (0,end) #清空输入框    e2.delete (0,end)    Button (root,text= "login", width=10,command=show). Grid (Row=3,column =0,sticky=w,padx=10,pady=5) button (root,text= "Exit", Width=10,command=root.quit). Grid (ROW=3,COLUMN=1,STICKY=E,PADX =10,pady=5) Mainloop ()

From tkinter Import *master = Tk () def test ():    if e1.get () = = "Hello":        print ("correct")        return True    else:        Print ("error")        E1.delete (0,end)        return Falsev=stringvar () e1=entry (master,textvariable=v,validate= "focusout ",         validatecommand=test) #validate为focusout的意思是, Validatecommand will be called when the cursor is removed                              # Invalidcommand is called E2=entry (Master) e1.pack (padx=10,pady=10) e2.pack (padx=10,pady=10) when the Validatecommand display is illegal Mainloop ()

Python Learning Tkinter notes (4)

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.