Commit c2c59dcb by BellCodeEditor

auto save

parent ee7b0e8f
Showing with 34 additions and 31 deletions
import tkinter
from tkinter import messagebox
import json
#为后续导入模块
with open('user.txt','r',encoding='utf-8')as f: #打开user文件进行读取
info=f.read()#读取数据
users=json.loads(info) #把json数据转化为python字典
with open('user.txt','r',encoding='utf-8')as f:
info =f.read() #读取
users =json.loads(info)#json转字典
def login_to_reg(): # 登录界面转注册界面
app_login.root.destroy() #关闭窗口
global app_reg #把局部变量转换为全局变量
app_reg=My_register()#调用方法打开页面
app_reg.show()#让页面显示出来
global app_reg #转换为全局变量
app_reg=My_register() #调用函数打开注册页面
app_reg.show() #显示注册页面
def reg_to_login(): # 注册界面转登录界面
app_reg.root.destroy()#关闭注册窗口
global app_login #把局部变量转换为全局变量
app_login=My_login() #打开登录窗口
app_login.show() #让页面显示出来
app_reg.root.destroy() #关闭窗口
global app_login #转换为全局变量
app_login=My_login() #调用函数打开登录页面
app_login.show()#显示登录页面
def register(): # 注册验证
name,password1,password2=app_reg.get_input() #读取用户填写的信息
if name =='' or password1=='' or password2=='': #盘对岸数据是否为空
messagebox.showwarning('警告','请填写完整的信息') #错误提示框
elif name in users: #判断用户名是否已存在
messagebox.showwarning('错误','用户名已存在') #错误提示框
elif password1 != password2: #判断两次密码输入的是否一致
messagebox.showwarning('错误','两次输入的密码不一致') #错误提示框
else: #用户输入信息没有问题
name,password1,password2=app_reg.get_input()#获取输入的内容
if name=='' or password1=='' or password2=='':
messagebox.showwarning('警告','请填写完整信息')
elif name in users:
messagebox.showwarning('警告','用户名已存在')
elif password1 != password2:
messagebox.showwarning('错误','两次输入的密码不一致')
else:
users[name]=password1
content=json.dumps(users) #把users转化为josn数据
with open('user.txt','w',encoding='utf-8')as f:
f.write(content) #把转化好的数据储存在user文件里面
#注册成功返回到登录页面
messagebox.showinfo('成功','注册成功')
reg_to_login() #打开登录窗口
content=json.dumps(users)
with open('user.txt','w',encoding='utf-8')as file:
file.write(content)
#注册成功,跳转到登录页
messagebox.showinfo('成功',"注册成功")
reg_to_login()
def login(): # 登录验证
name,password=app_login.get_input()#获取到数据
pwd=users.get(name) #查找用户名是否在users里面
name,password=app_login.get_input()
pwd=users.get(name)
if pwd ==password:
messagebox.showinfo('成功','登录成功')
else:
messagebox.showwarning('错误','用户名或密码错误')
messagebox.showinfo('错误','用户名或密码错误')
class My_login(): # 登录窗口
def __init__(self):
self.root = tkinter.Tk()
......
{"admin": "123456", "111": "111", "1111": "1111", "22222": "22222"}
\ No newline at end of file
{"admin": "123456", "111": "111", "1111": "1111", "22222": "22222", "123": "123123"}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment