吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1255|回复: 6
收起左侧

[Python 转载] 基于上次用户登录更新的注册界面设计——完善

[复制链接]
yuanting 发表于 2022-8-11 15:14
本帖最后由 yuanting 于 2022-8-11 17:01 编辑

首先先把设计思路整理好
首先是这一次新增的注册页面,设计思路
流程图.png
注册页面.png
注册情况.png


接下来是这次的登录注册界面的整体设计:
用户登录页面.png
下面是代码:

[Python] 纯文本查看 复制代码
import tkinter as tk
import tkinter.messagebox
import pickle
from PIL import Image, ImageTk
import urllib.request
root = tk.Tk()
root.title('欢迎进入云学习平台')
root.geometry('600x400+300+150')
canvas = tk.Canvas(root, height=400, width=600)
img = Image.open('E:p/ledo.png')
img1 = img.resize((600, 400), Image.ANTIALIAS)
img_root = ImageTk.PhotoImage(img1)
canvas.create_image(300, 200, image=img_root)
canvas.pack(side='top')
label1 = tk.Label(root, text="用户名:", bg="white", font=('宋体', 12), fg='black').place(x=300, y=150)
label2 = tk.Label(root, text="密  码:", bg="white", font=('宋体', 12), fg='black').place(x=300, y=200)
entry_name = tk.Entry(root)
entry_name.place(x=400, y=150)
entry_pwd = tk.Entry(root)
entry_pwd.place(x=400, y=200)
entry_pwd['show'] = '*'
def usr_log_in():
    name = entry_name.get()
    pwd = entry_pwd.get()
    try:
        with open('E:p\\usr_info.pickle', 'rb') as usr_file:
            usrs_info = pickle.load(usr_file)
    except FileNotFoundError:
        with open('E:p\\usr_info.pickle', 'wb')as usr_file:
            usrs_info = {'admin': 'admin'}
            pickle.dump(usrs_info, usr_file)
    if name in usrs_info:
        if pwd == usrs_info[name]:
            tk.messagebox.showinfo(title='welcome', message='欢迎您:'+name)
        else:
            tk.messagebox.showerror(message='密码错误')
    elif name == '' or pwd == '':
        tk.messagebox.showerror(message='用户名或密码为空')
    else:
        is_signup = tk.messagebox.askyesno('欢迎', '您还没有注册,是否现在注册')
        if is_signup:
            usr_sign_up()
def usr_sign_up():
    def signtowcg():
        nn = entry3.get()
        np = entry4.get()
        npf= entry5.get()
        try:
            with open('E:p\\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('错误', '用户名已存在')
        elif np == '' or nn == '':
            tk.messagebox.showerror('错误', '用户名或密码为空')
        elif np != npf:
            tk.messagebox.showerror('错误', '密码前后不一致')
        else:
            exist_usr_info[nn] = np
            with open('E:p\\usr_info.pickle', 'wb')as usr_file:
                pickle.dump(exist_usr_info, usr_file)
            tk.messagebox.showinfo('欢迎', '注册成功')
            window_sign_up.destroy()
    window_sign_up=tk.Toplevel(root)
    window_sign_up.geometry('350x200+420+280')
    window_sign_up.title('注册')
    label3=tk.Label(window_sign_up,text='用户名:')
    label3.place(x=20,y=15)
    entry3 = tk.Entry(window_sign_up)
    entry3.place(x=140,y=15)
    label4 = tk.Label(window_sign_up, text='请输入密码:')
    label4.place(x=20, y=55)
    entry4 = tk.Entry(window_sign_up)
    entry4.place(x=140, y=55)
    entry4['show']='*'
    label5= tk.Label(window_sign_up, text='请再次输入密码:')
    label5.place(x=20, y=95)
    entry5=tk.Entry(window_sign_up)
    entry5.place(x=140, y=95)
    entry5['show'] = '*'
    button4 = tk.Button(window_sign_up, text='确认注册', command=signtowcg)
    button4.place(x=140, y=140)
def delete():
    entry_name.delete(0,'end')
    entry_pwd.delete(0, 'end')
button1 = tk.Button(root, text='登录', font=('宋体', 12),fg='black', command=usr_log_in).place(x=300, y=270)
button2 = tk.Button(root, text='注册', font=('宋体', 12),fg='black', command=usr_sign_up).place(x=400, y=270)
button3 = tk.Button(root, text='退出', font=('宋体', 12),fg='black', command=delete).place(x=500, y=270)
root.mainloop()

显示一下运行效果图




测试1.jpg
测试4.jpg
测试3.jpg
测试2.jpg

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
kill零珏 + 1 + 1 热心回复!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

wa20521 发表于 2022-8-11 17:13
看着很不错呢
kill零珏 发表于 2022-8-11 17:25
 楼主| yuanting 发表于 2022-8-11 17:34
kill零珏 发表于 2022-8-11 17:25
最近也在tkinter,希望你继续更新,向你学习

更新是会更新的,不过时间就不定了,而且内容都是往后走的..不一定都是tkinter
kill零珏 发表于 2022-8-11 17:35
yuanting 发表于 2022-8-11 17:34
更新是会更新的,不过时间就不定了,而且内容都是往后走的..不一定都是tkinter

好嘞,会继续向你学习的其他内容
TYUSTxiaodong 发表于 2022-8-11 19:54
来膜拜膜拜,新手
virsnow 发表于 2022-10-3 16:04
不懂,只能看热闹!!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-12 06:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表