這篇文章主要介紹python做一個(gè)登錄注冊界面的方法,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括綠園網(wǎng)站建設(shè)、綠園網(wǎng)站制作、綠園網(wǎng)頁制作以及綠園網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,綠園網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到綠園省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
python做一個(gè)登錄注冊界面的方法:首先初始化一個(gè)window界面,并使用畫布實(shí)現(xiàn)歡迎的logo;然后用代碼實(shí)現(xiàn)登錄和注冊按鈕;接著并進(jìn)行登錄判斷代碼;最后完成注冊界面即可。

python做一個(gè)登錄注冊界面的方法:
一、登錄界面
1、首先初始化一個(gè)window界面
window = tk.Tk()
window.title('Welcome to Mofan Python')
window.geometry('450x300')
.
.
.
window.mainloop()2、界面需要一個(gè)歡迎的logo,主要使用畫布實(shí)現(xiàn)
#welcome image
#創(chuàng)建一個(gè)200X500的畫布
canvas = tk.Canvas(window,height = 200,width = 500)
#logo的路徑
image_file = tk.PhotoImage(file = 'E:\\welcome.gif')
#什么位置插入logo圖片
image = canvas.create_image(0,0,anchor = 'nw',image = image_file)
canvas.pack(side = 'top')3、接下來主要是登錄界面的代碼實(shí)現(xiàn)
tk.Label(window,text = 'Username:').place(x = 50,y = 150)
tk.Label(window,text = 'Password:').place(x = 50,y = 190)
var_usr_name = tk.StringVar()
#默認(rèn)值為MrZhangxd@python.com
var_usr_name.set('MrZhangxd@python.com')
var_usr_pwd = tk.StringVar()
entry_usr_name = tk.Entry(window,textvariable = var_usr_name)
entry_usr_name.place(x = 160,y = 150)
entry_usr_pwd = tk.Entry(window,textvariable = var_usr_pwd,show ='*')
entry_usr_pwd.place(x = 160,y = 190)4、登錄和注冊按鈕的實(shí)現(xiàn)代碼
#Login and Sign up button
# command = usr_login 調(diào)用usr_login函數(shù)
btn_login = tk.Button(window,text = 'Login',command = usr_login)
btn_login.place(x = 170,y = 230)
btn_sign_up = tk.Button(window,text = 'Sign up',command = usr_sign_up)
btn_sign_up.place(x = 270,y = 230)5、進(jìn)行登錄判斷代碼:主要用函數(shù)判斷
聲明usr_login函數(shù)
def usr_login():
usr_name = var_usr_name.get()
usr_pwd = var_usr_pwd.get()
try:
with open('usrs_info,pickle','rb') as usr_file:
usrs_info = pickle.load(usr_file)
except FileNotFoundError:
with open('usrs_info','wb') as usr_file:
usrs_info = {'admin':'admin'}
pickle.dump(usrs_info,usr_file)
if usr_name in usrs_info:
if usr_pwd == usrs_info[usr_name]:
tk.messagebox.showinfo(title = 'Welcome',message = 'How are you?' + usr_name)
else:
tk.messagebox.showinfo(message = 'Error,your password is wrong,try again.')
else:
is_sign_up = tk.messagebox.askyesno('Welcome','You hava not sign up yet.Sign up today?')
if is_sign_up:
usr_sign_up()登錄用戶不存在需要注冊
二、注冊界面
差不多和登錄界面一樣,然后不進(jìn)行細(xì)細(xì)的說明了,有不懂地方的可以給下文郵件地址發(fā)郵箱。
def usr_sign_up():
def sign_to_Mofan_Python():
np = new_pwd.get()
npf = new_pwd_confirm.get()
nn = new_name.get()
with open('usrs_info','rb') as usr_file:
exist_usr_info = pickle.load(usr_file)
if np!= npf:
tk.messagebox.showerror('Error','Password and confirm password must be the same!')
elif nn in exist_usr_info:
tk.messagebox.showerror('Error','The user has already 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()
new_name.set('MrZhangxd@python.com')
tk.Label(window_sign_up,text = 'Username:').place(x = 10,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 = 10,y = 50)
entry_new_pwd = tk.Entry(window_sign_up,textvariable = new_pwd,show = '*')
entry_new_pwd.place(x = 150,y = 50)
new_pwd_confirm = tk.StringVar()
tk.Label(window_sign_up,text = 'Confirm password:').place(x = 10,y = 90)
entry_comfirm_sign_up = tk.Entry(window_sign_up,textvariable = new_pwd_confirm,show = '*')
entry_comfirm_sign_up.place(x = 150,y = 90)
btn_comfirm_sign_up = tk.Button(window_sign_up,text = 'Sign up',command = sign_to_Mofan_Python)
btn_comfirm_sign_up.place(x = 150,y = 130)三、運(yùn)行界面截圖
登錄界面

注冊界面

以上是python做一個(gè)登錄注冊界面的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享名稱:python做一個(gè)登錄注冊界面的方法
網(wǎng)站網(wǎng)址:http://chinadenli.net/article12/jgggdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、域名注冊、微信公眾號(hào)、定制開發(fā)、企業(yè)建站、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)