Share tkinter using Python to write a login registration instance

Source: Internet
Author: User
This article is mainly for you to introduce the Python-based Tkinter writing landing registration interface, with a certain reference value, interested in small partners can refer to

Tkinter Create Login Registration interface, for your reference, the specific content as follows


Import Tkinter as Tkfrom tkinter import MessageBox #设置窗口居中def Window_info (): ws = Window.winfo_screenwidth () HS = WINDOW.W Info_screenheight () x = (WS/2)-$ y = (HS/2)-Print ("%d,%d"% (WS, HS)) return x, y #设置登陆窗口属性window = tk. Tk () Window.title (' Welcome to Parking Charge system ') A,b=window_info () window.geometry ("450x300+%d+%d"% (b)) #登陆界面的信息tk. Label (window,text= "Parking fee system", font= ("Song Body", "+"). 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) #显示输入框var_usr_name = tk. Stringvar () #显示默认账号var_usr_name. Set (' 1400370101 ') entry_usr_name=tk. Entry (Window,textvariable=var_usr_name) entry_usr_name.place (x=190,y=150) var_usr_pwd = tk. Stringvar () #设置输入密码后显示 * Number entry_usr_pwd = Tk. Entry (window,textvariable=var_usr_pwd,show= ' * ') entry_usr_pwd.place (x=190,y=190) #登陆函数def usr_login (): #获取输入的账号密码 Usr_name = Var_usr_name.get () usr_pwd = Var_usr_pwd.get () #获取存储的账户信息, here is the database, call the database query function, you can 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 is You? ' +usr_name) MainWindow () Else:tk.messagebox.sho Werror (message= ' Sorry, input error, please try again! ') else:is_sign_up = Tk.messagebox.askyesno (' Welcome ', ' You have not registered yet, are you now registered? ') if Is_sign_up:usr_sign_up () #注册账号def usr_sign_up (): Def Sign_to_pyhon (): NP = New_pwd.get () NPC = New_pwd_confirm.get ( ) 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 ', ' two times password input 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!  ') Except:tk.messagebox.showerror (' Registration failed! ') Window_sign_up.destroy () #创建top窗口作为注册窗口 window_sign_up = tk.  TopLevel (window) window_sign_up.geometry (' 350x200 ') window_sign_up.title (' Registration ')New_name = Tk. Stringvar () new_name.set (' 1400370115 ') 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= ' re-enter: '). 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= ' register ', Command=sign_to_pyhon) btn_again_sign_up.place (x=160,y=130) #登陆和注册按钮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 my login registration interface, using Tkinter, you can achieve a simple login and registration account, using the main Label,entry and button components.

Related Article

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.