Commit 5b494e9e by BellCodeEditor

save project

parent d342feb7
Showing with 85 additions and 7 deletions
import tkinter
from tkinter import *
from tkinter import messagebox
import json
class Note(): # 便签、笔记
def __init__(self):
self.root = tkinter.Tk()
self.root.geometry('300x340+1000+200')
self.root.title("我的便签-待办事项")
self.root.resizable(width=False, height=False)
self.bg_img = tkinter.PhotoImage(file="bg.png")
self.box = PhotoImage(file='box.png')
def show(self): # 布置窗口界面
# 画布
self.canvas = tkinter.Canvas(self.root, width=300, height=340)
self.canvas.create_image(0, 0, image=self.bg_img, anchor=NW)
self.canvas.place(x=0, y=0)
# 输入框
self.ent = tkinter.Entry(self.root, show=None,font=('宋体', 13),
bg="snow", width=25)
self.ent.place(x=10, y=310)
# 按钮
self.but = tkinter.Button(self.root,text='添加',font=('宋体', 12),
bg="lightblue", width=5, command=self.get_info)
self.but.place(x=240, y=305)
# 展示所有的文字
self.y = 20
self.val = 0 # 单选框的value参数
self.v = IntVar() # 设置关联变量
for info in alist:
self.canvas.create_text(40, self.y, text=info,
font=("宋体", 11), anchor=W, fill='#FF9900')
# 单选框组件
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30
def remove(self): # 清除选中的任务事件
num = self.v.get()
alist.pop(num)
# 更新用户待办事项
content = json.dumps(users)
with open("user.txt", "w", encoding="utf8") as file:
file.write(content)
# 重新渲染便签界面
self.canvas.destroy()
app.show()
def get_info(self): # 获取用户添加的新事件
info = self.ent.get()
self.ent.delete("0", END)
if info != "":
alist.append(info)
# 更新用户待办事项
content = json.dumps(users)
with open("user.txt", "w", encoding="utf8") as file:
file.write(content)
self.canvas.create_text(40,self.y,text=info,font=("宋体",11),
anchor=W, fill='#FF9900')
# 单选框组件
self.select = tkinter.Radiobutton(self.canvas,image=self.box,
value=self.val,variable=self.v,width=25, height=15,
borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.val += 1
self.y += 30
# 读取用户信息
with open("user.txt", "r", encoding="utf-8") as f:
info = f.read()
users = json.loads(info)
......@@ -26,8 +94,12 @@ def register(): # 注册验证
messagebox.showwarning("错误", "用户名已经存在!")
elif password1 != password2:
messagebox.showwarning("错误", "两次密码不一致!")
else:
users[name] = password1
else: # 通过验证
user_info = {}
user_info["password"] = password1
user_info["event"] = ["提示1:可以从输入框添加新任务",
"提示2:点击前面选择框,表示任务完成"]
users[name] = user_info
content = json.dumps(users)
with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容
file.write(content)
......@@ -36,10 +108,16 @@ def register(): # 注册验证
reg_to_login()
def login(): # 登录验证
global app,alist
name, password = app_login.get_input()
pwd = users.get(name)
if pwd == password:
messagebox.showinfo("成功", "登录成功")
# 验证用户名、密码是否正确
user_name = users.get(name)
if user_name != None and user_name["password"] == password:
alist = users[name]["event"]
app_login.root.destroy()
app = Note()
app.show()
app.root.mainloop()
else:
messagebox.showwarning("错误", "用户名或密码错误!")
......
{"admin": "admin", "python": "123456"}
\ No newline at end of file
{"admin": "admin", "python": "123456", "\u5965\u529b\u7ed9": {"password": "0529", "event": []}}
\ 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