python的tkinter如何实现简单登录

技术python的tkinter如何实现简单登录这篇文章主要介绍“python的tkinter如何实现简单登录”,在日常操作中,相信很多人在python的tkinter如何实现简单登录问题上存在疑惑,小编查阅了各式资料,

本文主要介绍“如何用python中的TKInters实现简单登录”。在日常操作中,相信很多人对于如何用python中的TKInters实现简单登录有所疑惑。边肖查阅了各种资料,整理出简单易用的操作方法,希望能帮你解答“如何用python中的TKInters实现简单登录”的疑惑!接下来,请和边肖一起学习!

00-1010参考文章:https://www.yisu.com/article/197751.htm

编写用户登录界面。用户可以登录帐户信息。如果帐户已经存在,他们可以直接登录。如果登录名或登录密码输入不正确,将提示您注册。如果该帐户不存在,将提示您注册。点击注册页面,输入注册信息。确认后,可以返回登录界面进行登录。进入个人主页可以修改个人信息。

通过python的tkinter实现简单的注册登录

importtkinterastk

from kinterimportmessagebox # importthisofixmessagebox error

进口泡菜

用户名=' '

#登录界面

defwelcome():

defusr_login():

usr_name=var_usr_name.get()

usr_pwd=var_usr_pwd.get()

尝试:

withopen('usrs_info.pickle ',' rb')asusr_file:

usrs_info=pickle.load(usr_file)

usr_file.close()

例外文件未找到错误:

withopen('usrs_info.pickle ',' wb')asusr_file:

usrs _ info={ ' admin ' : ' admin ' }

pickle.dump(usrs_info,usr_file)

usr_file.close()

ifusr _ nameinusrs _ info:

ifusr _ pwd==usrs _ info[usr _ name]:

(=NationalBureauofStandards)国家标准局

p;              tk.messagebox.showinfo(title='Welcome', message='How are you? ' + usr_name)
                # 进入主页
                global username
                username= usr_name
                print(username)
                window.destroy()
                index_page()
            else:
                tk.messagebox.showerror(message='Error, your password is wrong, try again.')
        else:
            is_sign_up = tk.messagebox.askyesno('Welcome', 'You have not signed up yet. Sign up today?')
            if is_sign_up:
                usr_sign_up()
    window = tk.Tk()
    window.title('Welcome to the login page!')
    window.geometry('450x300')
    # welcome image
    canvas = tk.Canvas(window, height=200, width=500)
    image_file = tk.PhotoImage(file='welcome.gif')
    image = canvas.create_image(0, 0, anchor='nw', image=image_file)
    canvas.pack(side='top')
    # user information
    tk.Label(window, text='User name: ').place(x=50, y=150)
    tk.Label(window, text='Password: ').place(x=50, 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)
    # login and sign up 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='Sign up', command=usr_sign_up)
    btn_sign_up.place(x=270, y=230)
    window.mainloop()
# 个人信息页面
def index_page():
    global username
    index_window = tk.Tk()
    index_window.title('请选择你要进行的操作')
    index_window.geometry('300x200')
    tk.Label(index_window,text="你好!"+username).place(x=50,y=50)
    # 修改个人信息
    def change_personal_info():
        # 新窗口
        change_info__window = tk.Toplevel()
        change_info__window.title('修改个人信息')
        change_info__window.geometry('400x300')
        # 修改个人信息点击页面
        def change_info_click():
            name = new_name.get()
            psw = new_password.get()
            conpsw = new_password_confirm.get()
            with open('usrs_info.pickle', 'rb') as f:
                usrs_info = pickle.load(f)
                f.close()
            if conpsw!= psw:
                tk.messagebox.showerror(title='Error', message='两次密码不一致请重新输入!')
            else:
                if name in usrs_info:
                    tk.messagebox.showerror(title='Error', message='用户名已存在,请重新换一个新用户名')
                else:
                    # 创建新
                    usrs_info.pop(username)
                    usrs_info[name] = psw
                    with open('usrs_info.pickle', 'wb') as file:
                        pickle.dump(usrs_info, file)
                        f.close()
                    tk.messagebox.showinfo(title='修改成功', message='修改成功!')
                    change_info__window.destroy()
                    tk.messagebox.showinfo(title='请重新登录!', message='请重新登录!')
                    index_window.destroy()
                    welcome()
        # 修改用户名变量
        new_name = tk.StringVar()
        tk.Label(change_info__window, text="用户名:").place(x=50, y=50)
        new_name_entry = tk.Entry(change_info__window, show=None, textvariable=new_name).place(x=120, y=50)
        # 修改新密码变量
        new_password = tk.StringVar()
        tk.Label(change_info__window, text='密码:').place(x=50, y=80)
        new_password_entry = tk.Entry(change_info__window, show="*", textvariable=new_password).place(x=120, y=80)
        # 修改新确认密码变量
        new_password_confirm = tk.StringVar()
        tk.Label(change_info__window, text="确认密码:").place(x=50, y=110)
        new_password_confirm_entry = tk.Entry(change_info__window, show="*", textvariable=new_password_confirm).place(x=120,
                                                                                                 y=110)
        # 修改信息按钮绑定
        sign_window_button = tk.Button(change_info__window, text='确认', command=change_info_click).place(x=150, y=140)
    # 修改个人信息按钮绑定
    change_info_button = tk.Button(index_window,text='修改个人信息',command=change_personal_info).place(x=100,y=100)
# 注册页面
def usr_sign_up():
    sign_up_window = tk.Toplevel()
    sign_up_window.title('注册')
    sign_up_window.geometry('400x200')
    # 注册点击事件
    def sign_up_hit():
        name = new_name.get()
        psw = new_password.get()
        conpsw = new_password_confirm.get()
        with open('usrs_info.pickle', 'rb') as usr_file:
            usrs_info = pickle.load(usr_file)
        if psw!=conpsw:
            tk.messagebox.showerror(title='Error', message='两次密码不一致请重新输入!')
        else:
            if name in usrs_info:
                tk.messagebox.showerror(title='Error', message='用户名已存在')
            else:
                # 创建新
                usrs_info[name] = psw
                with open('usrs_info.pickle', 'wb') as f:
                    pickle.dump(usrs_info,f)
                tk.messagebox.showinfo(title='注册成功', message='注册成功!')
                sign_up_window.destroy()
    # 注册名变量
    new_name = tk.StringVar()
    tk.Label(sign_up_window,text="注册名:").place(x=50,y=50)
    new_name_entry = tk.Entry(sign_up_window,show=None,textvariable=new_name).place(x=120,y=50)
    # 注册密码变量
    new_password = tk.StringVar()
    tk.Label(sign_up_window,text='密码:').place(x=50,y=80)
    new_password_entry = tk.Entry(sign_up_window,show="*",textvariable=new_password).place(x=120,y=80)
    # 注册确认密码变量
    new_password_confirm= tk.StringVar()
    tk.Label(sign_up_window,text="确认密码:").place(x=50,y=110)
    new_password_confirm_entry = tk.Entry(sign_up_window,show="*",textvariable=new_password_confirm).place(x=120,y=110)
    # 注册按钮和点击事件绑定
    sign_window_button = tk.Button(sign_up_window,text='注册',command=sign_up_hit).place(x=150,y=140)
welcome()

截图

登录页面

python的tkinter如何实现简单登录

注册页面

python的tkinter如何实现简单登录

个人主页

python的tkinter如何实现简单登录

修改个人信息失败

python的tkinter如何实现简单登录

修改个人信息成功

python的tkinter如何实现简单登录

重新登录twb

发现已注销除非重新注册。

python的tkinter如何实现简单登录

发现成功修改个人信息。登陆上。

python的tkinter如何实现简单登录

到此,关于“python的tkinter如何实现简单登录”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/140960.html

(0)

相关推荐

  • 怎么实现Zynq-7000开发环境的搭建

    技术怎么实现Zynq-7000开发环境的搭建本篇文章给大家分享的是有关怎么实现Zynq-7000开发环境的搭建,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

    攻略 2021年12月10日
  • PB在HTTP协议中怎么用

    技术PB在HTTP协议中怎么用小编给大家分享一下PB在HTTP协议中怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!客户端代码本例中分别演

    攻略 2021年11月23日
  • 怎么用Java实现判断括号的合法性

    技术怎么用Java实现判断括号的合法性本篇内容介绍了“怎么用Java实现判断括号的合法性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,

    攻略 2021年11月15日
  • 用图形画一幅画,用一张白纸怎么样绘画出一张图

    技术用图形画一幅画,用一张白纸怎么样绘画出一张图“绘见70年用图形画一幅画,画出新中国”一个才华横溢有望成为艺术大家的美术老师?,为大家呈现以绘画的方式表达对祖国的热爱。一张白纸经过我们的图图画画,使空白化作神奇。新手绘

    生活 2021年10月24日
  • 10组-Alpha冲刺-总结

    技术10组-Alpha冲刺-总结 10组-Alpha冲刺-总结[组长博客链接](https://www.cnblogs.com/Jimase/p/15585897.html)# 一、基本情况## 现场答

    礼包 2021年11月22日
  • QT乱翻书-Spin

    技术QT乱翻书-Spin QT乱翻书-Spin跳转到大纲 码云QT乱翻书-Spin#ifndef WIDGET_H
    #define WIDGET_H#include QWidgetnamespace U

    礼包 2021年12月14日