Tkinter creates login registration interface, tkinter Interface

Source: Internet
Author: User

Tkinter creates login registration interface, tkinter Interface

Import tkinter as tkfrom tkinter import messagebox # Set the window center def window_info (): ws = window. winfo_screenwidth () hs = window. winfo_screenheight () x = (ws/2)-200 y = (hs/2)-200 print ("% d, % d" % (ws, hs) return x, y # Set the login window attribute window = tk. tk () window. title ('Welcome to the parking lot billing system ') a, B = window_info () window. geometry ("450x300 + % d" % (a, B) # The Information tk on the logon page. label (window, text = "parking lot Charging System", font = ("", 32 )). place (x = 80, y = 50) tk. label (Window, text = "account :"). place (x = 120, y = 150) tk. label (window, text = "Password :"). place (x = 120, y = 190) # display the input box var_usr_name = tk. stringVar () # display the default account var_usr_name.set ('000000') entry_usr_name = tk. entry (window, textvariable = var_usr_name) entry_usr_name.place (x = 190, y = 150) var_usr_pwd = tk. stringVar () # Set the password to entry_usr_pwd = tk. entry (window, textvariable = var_usr_pwd, show = '*') entry_usr_pwd.place (x = 190, y = 190) # login function def usr_log In (): # obtain the input account password usr_name = var_usr_name.get () usr_pwd = var_usr_pwd.get () # obtain the storage account information. Here, the database is used to call the database query function, you can also use other methods, such as file dicts = SQL. load ('login') print (dicts) bool = False for row in dicts: print (row. get ("name") if usr_name = row ["name"]: bool = True pwd = row ["password"] print (row) if bool = True: if usr_pwd = pwd: tk. messagebox. showinfo (title = 'Welcome ', message = 'How are you? '+ Usr_name) mainwindow () else: tk. messagebox. showerror (message =' sorry, incorrect input. Please try again! ') Else: is_sign_up = tk. messagebox. askyesno ('Welcome', 'You have not registered yet. Are you registered now? ') If is_sign_up: usr_sign_up () # register account def usr_sign_up (): def sign_to_Pyhon (): np = new_pwd.get () npc = login () nn = new_name.get () dicts = SQL. load ('login') print (dicts) bool = False for row in dicts: if nn = row ["name"]: bool = True print (row) if np! = Npc: tk. messagebox. showerror ('Sorry, 'the two passwords are inconsistent! ') Elif bool: tk. messagebox. showerror ('Sorry,' this account already exists! ') Else: try: SQL. insert_login (str (nn), str (np) tk. messagebox. showinfo ('Welcome', 'You have registered successfully! ') Handle T: tk. messagebox. showerror (' registration failed! ') Window_sign_up.destroy () # create the top window as the registration window window_sign_up = tk. toplevel (window) window_sign_up.geometry ('350x200') window_sign_up.title ('registration') new_name = tk. stringVar () new_name.set ('20140901') tk. label (window_sign_up, text = 'account :'). place (x = 80, y = 10) entry_new_name = tk. entry (window_sign_up, textvariable = new_name) entry_new_name.place (x = 150, y = 10) new_pwd = tk. stringVar () tk. label (window_sign_up, text = 'password :'). place (x = 80, y = 50) entry_usr_pwd = tk. entry (window_sign_up, textvariable = new_pwd, show = '*') entry_usr_pwd.place (x = 150, y = 50) new_pwd_confirm = tk. stringVar () tk. label (window_sign_up, text = 'input again :'). place (x = 80, y = 90) entry_usr_pwd_again = tk. entry (window_sign_up, textvariable = new_pwd_confirm, show = '*') entry_usr_pwd_again.place (x = 150, y = 90) btn_again_sign_up = tk. button (window_sign_up, text = 'registration', command = sign_to_Pyhon) btn_again_sign_up.place (x = 160, y = 130) # login and Registration Button btn_login = tk. button (window, text = "login", command = usr_login) btn_login.place (x = 170, y = 230) btn_sign_up = tk. button (window, text = "register", command = usr_sign_up) btn_sign_up.place (x = 270, y = 230) window. mainloop ()

This is the login registration interface I wrote. Using tkinter, you can easily log on to and register an account, using the Label, Entry, and Button components.

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.