Commit 5aed26d8 by BellCodeEditor

auto save

parent 5682f627
Showing with 26 additions and 5 deletions
...@@ -2,6 +2,7 @@ import tkinter ...@@ -2,6 +2,7 @@ import tkinter
from tkinter import messagebox from tkinter import messagebox
import json 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 = json.loads(info)
...@@ -29,10 +30,29 @@ def register(): # 注册验证 ...@@ -29,10 +30,29 @@ def register(): # 注册验证
else: else:
messagebox.showinfo("提示","注册成功!") messagebox.showinfo("提示","注册成功!")
users[name] = password1 users[name] = password1
content = json.dumps(users)
with open('user.txt','w',encoding='utf-8') as f:
f.write(content)
reg_to_login() #注册成功转登录
def login(): # 登录验证 def login(): # 登录验证
pass global n1
name,password = app_login.get_input()
pwd = users.get(name)
result = str(users)
if n1 > 0:
if name in result:
if pwd == password:
messagebox.showinfo("提示","登录成功")
else:
n1 = n1 - 1
messagebox.showwarning("警告","密码错误,还有"+str(n1)+"次机会")
else:
n1 = n1 - 1
messagebox.showwarning("警告","用户名错误,还有"+str(n1)+"次机会")
else:
messagebox.showwarning("警告","次数用尽")
exit()
class My_login(): # 登录窗口 class My_login(): # 登录窗口
def __init__(self): def __init__(self):
self.root = tkinter.Tk() self.root = tkinter.Tk()
...@@ -123,6 +143,6 @@ class My_register(): # 注册窗口 ...@@ -123,6 +143,6 @@ class My_register(): # 注册窗口
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
n1 = 3
app_login = My_login() app_login = My_login()
app_login.show() app_login.show()
\ No newline at end of file
{"admin": "123456"} {"admin": "123456", "python": "111"}
\ No newline at end of file \ 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