Python tkinter using the-grid (GRID) layout manager

Source: Internet
Author: User

1 #writing a login window using Tkinter2 #The grid layout manager places the control in a two-dimensional table, and the main control is split into a series of rows and columns3 #Stricky Set the alignment, the parameter n/s/w/e the top, bottom, left, and right respectively.4 #ColumnSpan: Specifies that the control spans multiple columns of display5 #rowspan: Specifies that the control spans multiple lines of display6 #PADX, Pady set the horizontal and vertical interval sizes respectively7 8 ImportTkinter as TK9 TenRoot =tk. Tk () OneRoot.title ("Please login") A  -  - defReg (): the     " "Login Check" " -Username =E_user.get () -passwd =E_pwd.get () -Len_user =len (username) +Len_pwd =Len (passwd) -     ifUsername = ='Admin'  andpasswd = ='123': +l_msg['text'] ='Login Successful! ' Al_msg['FG'] ='Green' at     Else: -L_msg.configure (text='Login failed! ', fg='Red') -     #e_user.delete (0, Len_user) # Empty the input box - e_pwd.delete (0, Len_pwd) -  -  in #sign-in results tips -L_msg = Tk. Label (Root, text="') toL_msg.grid (row=0, columnspan=2)#show across two columns +  - #First line user name input box theL_user = Tk. Label (Root, text='User name:') *L_user.grid (Row=1, sticky=tk. W) $E_user =tk. Entry (Root)Panax NotoginsengE_user.grid (Row=1, Column=1, STICKY=TK. E, padx=3) -  the #Second line password input box +L_pwd = Tk. Label (Root, text='Password:') AL_pwd.grid (row=2, sticky=tk. E) theE_pwd =tk. Entry (Root) +e_pwd['Show'] ='*'  #Hide Display -E_pwd.grid (row=2, Column=1, STICKY=TK. E, padx=3) $  $ #Third Line Login button -F_BTN =tk. Frame (Root) -B_login = Tk. Button (F_BTN, text='Login', Width=6, command=reg) theB_login.grid (row=0, column=0) -B_cancel = Tk. Button (F_BTN, text='Cancel', Width=6, command=root.quit)WuyiB_cancel.grid (row=0, Column=1) theF_btn.grid (row=3, columnspan=2, pady=10) -  Wu Root.mainloop () -  About #Original button Layout $ #B_login = tk. Button (root, text= ' login ', Command=reg) - #B_login.grid (row=3, Column=1, STICKY=TK. W, pady=10) - #b_cancel = tk. Button (Root, text= ' Cancel ', command=root.quit) - #B_cancel.grid (row=3, column=1)

Python tkinter using the-grid (GRID) layout manager

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.