Commit 01688c12 by BellCodeEditor

auto save

parent a03cf3e9
Showing with 11 additions and 4 deletions
...@@ -4,8 +4,11 @@ import json ...@@ -4,8 +4,11 @@ import json
with open("user.txt", "r", encoding="utf-8") as f: with open("user.txt", "r", encoding="utf-8") as f:
info = f.read() info = f.read()
users = json.loads(info) users = {}
print(users) if info != "":
users = json.loads(info)
print(users)
# print(users)
def login_to_reg(): # 登录界面转注册界面 def login_to_reg(): # 登录界面转注册界面
app_login.root.destroy() app_login.root.destroy()
global app_reg global app_reg
...@@ -19,6 +22,7 @@ def reg_to_login(): # 注册界面转登录界面 ...@@ -19,6 +22,7 @@ def reg_to_login(): # 注册界面转登录界面
app_login.show() app_login.show()
def register(): # 注册验证 def register(): # 注册验证
print(app_reg.get_input())
name,password1,password2 = app_reg.get_input() name,password1,password2 = app_reg.get_input()
if name =="" or password2 == "" or password1=="": if name =="" or password2 == "" or password1=="":
messagebox.showwarning("警告", "请填写完整的注册资料") messagebox.showwarning("警告", "请填写完整的注册资料")
...@@ -28,7 +32,7 @@ def register(): # 注册验证 ...@@ -28,7 +32,7 @@ def register(): # 注册验证
messagebox.showwarning("错误", "两次密码不一致!") messagebox.showwarning("错误", "两次密码不一致!")
else: else:
users[name] = password1 users[name] = password1
conntent = json.dumps(users) content = json.dumps(users,ensure_ascii=False)
with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容 with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容
file.write(content) file.write(content)
# 注册成功,跳往登陆界面 # 注册成功,跳往登陆界面
...@@ -63,7 +67,7 @@ class My_login(): # 登录窗口 ...@@ -63,7 +67,7 @@ class My_login(): # 登录窗口
l.place(x=50, y=140) l.place(x=50, y=140)
# Entry单行文本输入框:用户名、密码 # Entry单行文本输入框:用户名、密码
self.e1 = tkinter.Entry(self.root, show=None, font=('宋体', 14), self.e1 = k;lhggyugguhuhuno9yu7hy ib,bm, 8yyb uuu hkjn (self.root, show=None, font=('宋体', 14),
bg="light grey", width=18) # 显示成明文形式 bg="light grey", width=18) # 显示成明文形式
self.e2 = tkinter.Entry(self.root, show='*', font=('宋体', 14), self.e2 = tkinter.Entry(self.root, show='*', font=('宋体', 14),
width=18) # 显示成密文形式 width=18) # 显示成密文形式
...@@ -129,6 +133,7 @@ class My_register(): # 注册窗口 ...@@ -129,6 +133,7 @@ class My_register(): # 注册窗口
def get_input(self): # 获取提交的注册信息 def get_input(self): # 获取提交的注册信息
self.name = self.e1.get() self.name = self.e1.get()
print("self.name",self.name )
self.password1 = self.e2.get() self.password1 = self.e2.get()
self.password2 = self.e3.get() self.password2 = self.e3.get()
return self.name, self.password1, self.password2 return self.name, self.password1, self.password2
......
{"测试": "123456", "ceshi": "111111", "名字": "123456", "中文": "1111111"}
\ 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