資源簡(jiǎn)介
使用python tkinter寫的登陸窗口,源碼需要的可以參考下

代碼片段和文件信息
import?tkinter?as?tk
import?pickle
import?tkinter.messagebox
window=tk.Tk()
window.title(‘歡迎登陸OBD擴(kuò)容工具‘)
window.geometry(‘450x300‘)
canvas=tk.Canvas(windowheight=200width=500)
image_file=tk.PhotoImage(file=‘welcome.gif‘)
image=canvas.create_image(00anchor=tk.NWimage=image_file)
canvas.pack(side=tk.TOP)
tk.Label(windowtext=“用戶名:“).place(x=50y=150?anchor=‘nw‘)
tk.Label(windowtext=“密碼:“).place(x=50y=190?anchor=‘nw‘)
var_usr_name=tk.StringVar()
var_usr_name.set(‘example@python.com‘)
entry_usr_name=tk.Entry(windowtextvariable=var_usr_name)
entry_usr_name.place(x=160y=150)
var_usr_pwd=tk.StringVar()
entry_usr_pwd=tk.Entry(windowtextvariable=var_usr_pwdshow=‘*‘)
entry_usr_pwd.place(x=160y=190)
def?usr_login():
????usr_name=var_usr_name.get()
????usr_pwd=var_usr_pwd.get()
????try:
????????with?open(‘usrs_info.pickle‘‘rb‘)?as?f:
????????????user_info=pickle.load(f)
????except?FileNotFoundError:
????????with?open(‘usrs_info.pickle‘‘wb‘)?as?f:
????????????user_info={‘a(chǎn)dmin‘:‘a(chǎn)dmin‘}
????????????pickle.dump(user_infof)
????if?usr_name?in?user_info:
????????if?usr_pwd==user_info[usr_name]:
????????????tk.messagebox.showinfo(‘歡迎?%s‘%usr_name)
????????else:
????????????tk.messagebox.showerror(‘密碼錯(cuò)誤‘)
????else:
????????is_sign_up=tk.messagebox.askyesno(‘賬號(hào)不存在,是否注冊(cè)?‘)
????????if?is_sign_up:
????????????usr_sign_up()
def?usr_sign_up():
????def?sign_to_Mofan_Python():
????????##以下三行就是獲取我們注冊(cè)時(shí)所輸入的信息
????????np?=?new_pwd.get()
????????npf?=?new_pwd_confirm.get()
????????nn?=?new_name.get()
????????##這里是打開(kāi)我們記錄數(shù)據(jù)的文件,將注冊(cè)信息讀出
????????with?open(‘usrs_info.pickle‘?‘rb‘)?as?usr_file:
????????????exist_usr_info?=?pickle.load(usr_file)
????????##這里就是判斷,如果兩次密碼輸入不一致,則提示‘‘Error‘?‘Password?and?confirm?password?must?be?the?same!‘‘
????????if?np?!=?npf:
????????????tk.messagebox.showerror(‘Error‘?‘Password?and?confirm?password?must?be?the?same!‘)
????????##如果用戶名已經(jīng)在我們的數(shù)據(jù)文件中,則提示‘‘Error‘?‘The?user?has?already?signed?up!‘‘
????????elif?nn?in?exist_usr_info:
????????????tk.messagebox.showerror(‘Error‘?‘The?user?has?already?signed?up!‘)
????????##最后如果輸入無(wú)以上錯(cuò)誤,則將注冊(cè)輸入的信息記錄到文件當(dāng)中,并提示注冊(cè)成功‘‘Welcome‘?‘You?have?successfully?signed?up!‘‘
????????##然后銷毀窗口。
????????else:
????????????exist_usr_info[nn]?=?np
????????????with?open(‘usrs_info.pickle‘?‘wb‘)?as?usr_file:
????????????????pickle.dump(exist_usr_info?usr_file)
????????????tk.messagebox.showinfo(‘Welcome‘?‘You?have?successfully?signed?up!‘)
????????????##然后銷毀窗口。
????????????window_sign_up.destroy()
????window_sign_up?=?tk.Toplevel(window)
????window_sign_up.geometry(‘350x200‘)
????window_sign_up.title(‘Sign?up?window‘)
????new_name?=?tk.StringVar()#將輸入的注冊(cè)名賦值給變量
????new_name.set(‘example@python.com‘)#將最初顯示定為‘example@python.com‘
????tk.Label(window_sign_up?text=‘User?name:?‘).place(x=10?y=?10)#將‘User?name:‘放置在坐標(biāo)(1010)。
????entry_new_name?=?tk.Entry(window_sign_up?textvariable=new_name)#創(chuàng)建一個(gè)注冊(cè)名的‘entry‘,變量為‘new_name‘
????ent
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????4365??2018-10-13?16:01??新建文件夾?(4)\login.py
?????文件???????79059??2018-10-13?12:26??新建文件夾?(4)\welcome.gif
?????目錄???????????0??2018-10-13?16:03??新建文件夾?(4)\
評(píng)論
共有 條評(píng)論