最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python tkinter制作用戶登錄界面的簡單實(shí)現(xiàn)

 更新時(shí)間:2021年04月09日 09:22:56   作者:獨(dú)孤尚亮dugushangliang  
這篇文章主要介紹了python tkinter制作用戶登錄界面的簡單實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

本文只是幾年前學(xué)習(xí)的tkinter的時(shí)候?qū)懙臏y試程序,十分之簡陋,只是學(xué)習(xí)用,沒什么其他用處。

學(xué)習(xí)一下莫煩Python的tkinter教程,根據(jù)教程制作了用戶登錄注冊頁?;竟δ転闄z查登錄、注冊。

運(yùn)行如下:

​​​​​​

代碼如下:

# -*- coding: utf-8 -*-
"""
Created on Sun Aug  5 10:34:10 2018
@author: Administrator
"""
import tkinter as tk
import tkinter.messagebox
import pickle
#窗口
window=tk.Tk()
window.title('歡迎進(jìn)入學(xué)習(xí)系統(tǒng)')
window.geometry('450x300')
#畫布放置圖片
canvas=tk.Canvas(window,height=300,width=500)
imagefile=tk.PhotoImage(file='qm.png')
image=canvas.create_image(0,0,anchor='nw',image=imagefile)
canvas.pack(side='top')
#標(biāo)簽 用戶名密碼
tk.Label(window,text='用戶名:').place(x=100,y=150)
tk.Label(window,text='密碼:').place(x=100,y=190)
#用戶名輸入框
var_usr_name=tk.StringVar()
entry_usr_name=tk.Entry(window,textvariable=var_usr_name)
entry_usr_name.place(x=160,y=150)
#密碼輸入框
var_usr_pwd=tk.StringVar()
entry_usr_pwd=tk.Entry(window,textvariable=var_usr_pwd,show='*')
entry_usr_pwd.place(x=160,y=190)
 
#登錄函數(shù)
def usr_log_in():
    #輸入框獲取用戶名密碼
    usr_name=var_usr_name.get()
    usr_pwd=var_usr_pwd.get()
    #從本地字典獲取用戶信息,如果沒有則新建本地?cái)?shù)據(jù)庫
    try:
        with open('usr_info.pickle','rb') as usr_file:
            usrs_info=pickle.load(usr_file)
    except FileNotFoundError:
        with open('usr_info.pickle','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='歡迎您:'+usr_name)
        else:
            tk.messagebox.showerror(message='密碼錯(cuò)誤')
    #用戶名密碼不能為空
    elif usr_name=='' or usr_pwd=='' :
        tk.messagebox.showerror(message='用戶名或密碼為空')
    #不在數(shù)據(jù)庫中彈出是否注冊的框
    else:
        is_signup=tk.messagebox.askyesno('歡迎','您還沒有注冊,是否現(xiàn)在注冊')
        if is_signup:
            usr_sign_up()
#注冊函數(shù)
def usr_sign_up():
    #確認(rèn)注冊時(shí)的相應(yīng)函數(shù)
    def signtowcg():
        #獲取輸入框內(nèi)的內(nèi)容
        nn=new_name.get()
        np=new_pwd.get()
        npf=new_pwd_confirm.get()
 
        #本地加載已有用戶信息,如果沒有則已有用戶信息為空
        try:
            with open('usr_info.pickle','rb') as usr_file:
                exist_usr_info=pickle.load(usr_file)
        except FileNotFoundError:
            exist_usr_info={}           
            
        #檢查用戶名存在、密碼為空、密碼前后不一致
        if nn in exist_usr_info:
            tk.messagebox.showerror('錯(cuò)誤','用戶名已存在')
        elif np =='' or nn=='':
            tk.messagebox.showerror('錯(cuò)誤','用戶名或密碼為空')
        elif np !=npf:
            tk.messagebox.showerror('錯(cuò)誤','密碼前后不一致')
        #注冊信息沒有問題則將用戶名密碼寫入數(shù)據(jù)庫
        else:
            exist_usr_info[nn]=np
            with open('usr_info.pickle','wb') as usr_file:
                pickle.dump(exist_usr_info,usr_file)
            tk.messagebox.showinfo('歡迎','注冊成功')
            #注冊成功關(guān)閉注冊框
            window_sign_up.destroy()
    #新建注冊界面
    window_sign_up=tk.Toplevel(window)
    window_sign_up.geometry('350x200')
    window_sign_up.title('注冊')
    #用戶名變量及標(biāo)簽、輸入框
    new_name=tk.StringVar()
    tk.Label(window_sign_up,text='用戶名:').place(x=10,y=10)
    tk.Entry(window_sign_up,textvariable=new_name).place(x=150,y=10)
    #密碼變量及標(biāo)簽、輸入框
    new_pwd=tk.StringVar()
    tk.Label(window_sign_up,text='請輸入密碼:').place(x=10,y=50)
    tk.Entry(window_sign_up,textvariable=new_pwd,show='*').place(x=150,y=50)    
    #重復(fù)密碼變量及標(biāo)簽、輸入框
    new_pwd_confirm=tk.StringVar()
    tk.Label(window_sign_up,text='請?jiān)俅屋斎朊艽a:').place(x=10,y=90)
    tk.Entry(window_sign_up,textvariable=new_pwd_confirm,show='*').place(x=150,y=90)    
    #確認(rèn)注冊按鈕及位置
    bt_confirm_sign_up=tk.Button(window_sign_up,text='確認(rèn)注冊',
                                 command=signtowcg)
    bt_confirm_sign_up.place(x=150,y=130)
#退出的函數(shù)
def usr_sign_quit():
    window.destroy()
#登錄 注冊按鈕
bt_login=tk.Button(window,text='登錄',command=usr_log_in)
bt_login.place(x=140,y=230)
bt_logup=tk.Button(window,text='注冊',command=usr_sign_up)
bt_logup.place(x=210,y=230)
bt_logquit=tk.Button(window,text='退出',command=usr_sign_quit)
bt_logquit.place(x=280,y=230)
#主循環(huán)
window.mainloop()

到此這篇關(guān)于python tkinter制作用戶登錄界面的簡單實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)python tkinter用戶登錄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

获嘉县| 龙州县| 射阳县| 卢氏县| 中西区| 浦东新区| 天津市| 仙游县| 临潭县| 环江| 台东县| 高尔夫| 梧州市| 邯郸市| 明光市| 南部县| 梅河口市| 米林县| 台山市| 怀柔区| 婺源县| 玛纳斯县| 凤凰县| 中江县| 陆川县| 龙门县| 新密市| 合川市| 济南市| 青铜峡市| 和平区| 商洛市| 大冶市| 吉水县| 城市| 临邑县| 桐乡市| 宣化县| 宣恩县| 临沂市| 吴堡县|