Commit 32e78883 by BellCodeEditor

save project

parent 72781b29
Showing with 31 additions and 12 deletions
...@@ -3,8 +3,13 @@ from tkinter import * ...@@ -3,8 +3,13 @@ from tkinter import *
from tkinter import messagebox from tkinter import messagebox
import json import json
alist = ["星期六下午打篮球", "星期天下午和小美一起看电影", alist = ["提示1:填写待办事项并添加可添加任务","提示2:点击选项框可删除后面的任务"]
"12月18日给蒂法过生日", "12.24送妈妈圣诞礼物"]
def save_info():
users[name]["text"] = self.text_list
content = json.dumps(users)
with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容
file.write(content)
class Note(): # 便签、笔记 class Note(): # 便签、笔记
def __init__(self): def __init__(self):
...@@ -14,11 +19,19 @@ class Note(): # 便签、笔记 ...@@ -14,11 +19,19 @@ class Note(): # 便签、笔记
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")
def save_info(self):
user_list["text"] = self.text_list
users[name] = user_list
self.content = json.dumps(users)
with open("user.txt", "w", encoding="utf-8") as file: # "w"每次写入都覆盖原来的内容
file.write(self.content)
def remove(self): def remove(self):
self.num_get = self.v.get() self.num_get = self.v.get()
alist.pop(self.num_get) self.text_list.pop(self.num_get)
self.canvas.destroy() self.canvas.destroy()
self.show() self.show()
self.save_info()
def show(self): # 布置窗口界面 def show(self): # 布置窗口界面
# 画布 # 画布
...@@ -34,11 +47,12 @@ class Note(): # 便签、笔记 ...@@ -34,11 +47,12 @@ class Note(): # 便签、笔记
bg="lightblue", width=5, command=self.get_info) bg="lightblue", width=5, command=self.get_info)
self.but.place(x=240, y=305) self.but.place(x=240, y=305)
# 展示所有的文字 # 展示所有的文字
self.text_list = user_list.get("text")
self.box = tkinter.PhotoImage(file='box.png') self.box = tkinter.PhotoImage(file='box.png')
self.y = 20 self.y = 20
self.num = 0 self.num = 0
self.v = tkinter.IntVar() self.v = tkinter.IntVar()
for info in alist: for info in self.text_list:
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.a = tkinter.Radiobutton(self.canvas,image=self.box,height=13, self.a = tkinter.Radiobutton(self.canvas,image=self.box,height=13,
...@@ -52,7 +66,7 @@ class Note(): # 便签、笔记 ...@@ -52,7 +66,7 @@ class Note(): # 便签、笔记
info = self.ent.get() info = self.ent.get()
self.ent.delete("0", END) self.ent.delete("0", END)
if info != "": if info != "":
alist.append(info) self.text_list.append(info)
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.a = tkinter.Radiobutton(self.canvas,image=self.box,height=13, self.a = tkinter.Radiobutton(self.canvas,image=self.box,height=13,
...@@ -61,6 +75,7 @@ class Note(): # 便签、笔记 ...@@ -61,6 +75,7 @@ class Note(): # 便签、笔记
self.a.place(x=-27,y=self.y-15) self.a.place(x=-27,y=self.y-15)
self.num += 1 self.num += 1
self.y += 30 self.y += 30
self.save_info()
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()
...@@ -87,7 +102,10 @@ def register(): # 注册验证 ...@@ -87,7 +102,10 @@ def register(): # 注册验证
elif password1 != password2: elif password1 != password2:
messagebox.showwarning("错误", "两次密码不一致!") messagebox.showwarning("错误", "两次密码不一致!")
else: else:
users[name] = password1 user_info = {}
user_info["password"] = password1
user_info["text"] = alist
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)
...@@ -96,9 +114,10 @@ def register(): # 注册验证 ...@@ -96,9 +114,10 @@ def register(): # 注册验证
reg_to_login() reg_to_login()
def login(): # 登录验证 def login(): # 登录验证
global app global app,user_list,name
name, password = app_login.get_input() name, password = app_login.get_input()
pwd = users.get(name) user_list = users.get(name)
pwd = user_list.get("password")
if pwd == password: if pwd == password:
app_login.root.destroy() app_login.root.destroy()
app = Note() app = Note()
...@@ -111,7 +130,7 @@ class My_login(): # 登录窗口 ...@@ -111,7 +130,7 @@ class My_login(): # 登录窗口
def __init__(self): def __init__(self):
self.root = tkinter.Tk() self.root = tkinter.Tk()
self.root.title("登录窗口") self.root.title("登录窗口")
self.root.geometry('400x300+500+300') self.root.geometry('400x300+50+50')
self.root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸 self.root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸
def show(self): # 登录界面的所有控件 def show(self): # 登录界面的所有控件
...@@ -152,7 +171,7 @@ class My_register(): # 注册窗口 ...@@ -152,7 +171,7 @@ class My_register(): # 注册窗口
def __init__(self): def __init__(self):
self.root = tkinter.Tk() self.root = tkinter.Tk()
self.root.title("注册窗口") self.root.title("注册窗口")
self.root.geometry('400x320+500+300') self.root.geometry('400x320+50+50')
self.root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸 self.root.resizable(width=False, height=False) # True可以拉伸,False不能拉伸
def show(self): # 注册界面的所有控件 def show(self): # 注册界面的所有控件
......
{"admin": "admin", "python": "123456", "ttt": "123"} {"admin": {"password": "123", "text": ["aaaa"]}}
\ 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