Commit 2b388249 by BellCodeEditor

auto save

parent 1d2a1d0a
Showing with 18 additions and 17 deletions
...@@ -11,13 +11,14 @@ class Note(): # 便签、笔记 ...@@ -11,13 +11,14 @@ class Note(): # 便签、笔记
self.root.title("我的便签-待办事项") self.root.title("我的便签-待办事项")
self.root.resizable(width=False, height=False) self.root.resizable(width=False, height=False)
self.bg_img = tkinter.PhotoImage(file="bg.png") self.bg_img = tkinter.PhotoImage(file="bg.png")
self.box = PhotoImage(file='box.png') self.bg_box= tkinter.PhotoImage(file='box.png')
def show(self): # 布置窗口界面 def show(self): # 布置窗口界面
# 画布 # 画布
self.canvas = tkinter.Canvas(self.root, width=300, height=340) self.canvas = tkinter.Canvas(self.root, width=300, height=340)
self.canvas.create_image(0, 0, image=self.bg_img, anchor=NW) self.canvas.create_image(0, 0, image=self.bg_img, anchor=NW)
self.canvas.place(x=0, y=0) self.canvas.place(x=0, y=0)
# 输入框 # 输入框-
self.ent = tkinter.Entry(self.root, show=None,font=('宋体', 13), self.ent = tkinter.Entry(self.root, show=None,font=('宋体', 13),
bg="snow", width=25) bg="snow", width=25)
self.ent.place(x=10, y=310) self.ent.place(x=10, y=310)
...@@ -27,19 +28,17 @@ class Note(): # 便签、笔记 ...@@ -27,19 +28,17 @@ class Note(): # 便签、笔记
self.but.place(x=240, y=305) self.but.place(x=240, y=305)
# 展示所有的文字 # 展示所有的文字
self.y = 20 self.y = 20
self.val = 0 #单选框的value参数 self.var=0 #单选框参数
self.v = IntVar() #设置关联变量 self.v=IntVar() #设置关联变量
for info in alist: for info in alist:
self.canvas.create_text(40, self.y, text=info, self.canvas.create_text(40, self.y, text=info,
font=("宋体", 11), anchor=W, fill='#FF9900') 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.selet=tkinter.Radiobutton(self.canvas , image=self.bg_box,value=self.var,variable=self.v,width=25,height=15,borderwidth=0,command=self.remove)
self.select.place(x=-20 ,y=self.y-10) self.selet.place(x=-20,y=self.y-10)
self.val+=1
self.y += 30 self.y += 30
def remove(self): def remove(self):
num =self.v.get() num = self.v.get()
alist.pop(num) alist.pop(num)
#更新用户待办事项
content=json.dumps(users) content=json.dumps(users)
with open('user.txt','w',encoding='utf-8')as file: with open('user.txt','w',encoding='utf-8')as file:
file.write(content) file.write(content)
...@@ -55,13 +54,14 @@ class Note(): # 便签、笔记 ...@@ -55,13 +54,14 @@ class Note(): # 便签、笔记
file.write(content) file.write(content)
self.canvas.create_text(40,self.y,text=info,font=("宋体",11), self.canvas.create_text(40,self.y,text=info,font=("宋体",11),
anchor=W, fill='#FF9900') 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.selet=tkinter.Radiobutton(self.canvas , image=self.bg_box,value=self.var,variable=self.v,width=25,height=15,borderwidth=0,command=self.remove)
self.select.place(x=-20 ,y=self.y-10) self.selet.place(x=-20,y=self.y-10)
self.val+=1
self.y += 30 self.y += 30
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)
...@@ -89,8 +89,9 @@ def register(): # 注册验证 ...@@ -89,8 +89,9 @@ def register(): # 注册验证
else: else:
user_info={} user_info={}
user_info['password']=password1 user_info['password']=password1
user_info['event']=['提示1:在输入框添加新的任务','提示2:点击单选框,表示任务完成'] user_info['event']=['提示1:','提示2:']
users[name] = user_info users[name]=user_info
content = json.dumps(users) content = json.dumps(users)
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)
...@@ -99,11 +100,11 @@ def register(): # 注册验证 ...@@ -99,11 +100,11 @@ def register(): # 注册验证
reg_to_login() reg_to_login()
def login(): # 登录验证 def login(): # 登录验证
global app,alist #把局部变量转换成全局变量 global app ,alist
name, password = app_login.get_input() name, password = app_login.get_input()
user_name = users.get(name) user_name = users.get(name)
if user_name != None and user_name['password']==password: if user_name != None and user_name['password']==password:
alist=users[name]['event'] alist = users[name]['event']
app_login.root.destroy() app_login.root.destroy()
app=Note() app=Note()
app.show() app.show()
......
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