Commit 1fb6125f by BellCodeEditor

auto save

parent 2b388249
Showing with 303 additions and 44 deletions
import tkinter
from tkinter import *
alist = ["星期六下午打篮球", "星期天下午和小美一起看电影",
"12月18日给蒂法过生日","12.24送妈妈圣诞礼物"]
class Note(): # 便签、笔记
from tkinter import *
alist = ["星期六下午打篮球", "星期天下午和小美一起看电影",
"12月18日给蒂法过生日", "12.24送妈妈圣诞礼物"]
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') #导入背景图
def show(self): # 布置窗口界面
#画布
self.canvas = tkinter.Canvas(self.root ,width=300,height=340,bg='lightblue')
self.canvas.create_image(0,0,image=self.bg_img ,anchor=NW)
self.canvas.place(x=0,y=0)
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 = 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 = 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.y = 20
self.var=0
self.v=IntVar()
for info in alist:
self.canvas.create_text(40,self.y,text=info,font=('楷体',11),anchor=W,fill='#0000FF')
self.y+=30
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.var,variable=self.v,width=25,height=15,borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.y += 30
def remove(self):
num=self.v.get()
alist.pop(num)
self.canvas.destroy()
app.show()
def get_info(self):
info = self.ent.get()
if info != '':
self.ent.delete('0',END) #清除从0索引到最后的内容
self.ent.delete("0", END)
if info != "":
alist.append(info)
self.canvas.create_text(40,self.y,text=info,font=('楷体',11),anchor=W,fill='#0000FF')
self.y+=30
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.var,variable=self.v,width=25,height=15,borderwidth=0,command=self.remove)
self.select.place(x=-20,y=self.y-10)
self.y += 30
app = Note()
app = Note()
app.show()
app.root.mainloop()
\ No newline at end of file
app.root.mainloop()
......@@ -11,14 +11,13 @@ class Note(): # 便签、笔记
self.root.title("我的便签-待办事项")
self.root.resizable(width=False, height=False)
self.bg_img = tkinter.PhotoImage(file="bg.png")
self.bg_box= tkinter.PhotoImage(file='box.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)
......@@ -28,40 +27,41 @@ class Note(): # 便签、笔记
self.but.place(x=240, y=305)
# 展示所有的文字
self.y = 20
self.var=0 #单选框参数
self.v=IntVar() #设置关联变量
self.var=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.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.selet.place(x=-20,y=self.y-10)
font=("宋体", 11), anchor=W, fill='#FF9900')
self.select = tkinter.Radiobutton(self.canvas,image=self.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.y += 30
def remove(self):
num = self.v.get()
alist.pop(num)
content=json.dumps(users)
#更新
content = json.dumps(users)
with open('user.txt','w',encoding='utf-8')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)
content = json.dumps(users)
with open('user.txt','w',encoding='utf-8')as file:
file.write(content)
self.canvas.create_text(40,self.y,text=info,font=("宋体",11),
anchor=W, fill='#FF9900')
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.selet.place(x=-20,y=self.y-10)
self.select = tkinter.Radiobutton(self.canvas,image=self.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.y += 30
with open("user.txt", "r", encoding="utf-8") as f:
info = f.read()
users = json.loads(info)
......@@ -100,11 +100,11 @@ def register(): # 注册验证
reg_to_login()
def login(): # 登录验证
global app ,alist
global app,alist #转换为全局变量
name, password = app_login.get_input()
user_name = users.get(name)
if user_name != None and user_name['password']==password:
alist = users[name]['event']
alist=users[name]['event']
app_login.root.destroy()
app=Note()
app.show()
......
{"m": {"password": "m", "event": []}}
\ No newline at end of file
{"123": {"password": "123", "event": ["\u63d0\u793a1\uff1a\u53ef\u4ee5\u540c\u8f93\u5165\u6846\u6dfb\u52a0\u65b0\u4efb\u52a1", "\u63d0\u793a2:\u70b9\u51fb\u524d\u9762\u9009\u62e9\u6846\uff0c\u8868\u793a\u4efb\u52a1\u5b8c\u6210", "1231"]}, "qqq": {"password": "qqq", "event": []}}
\ No newline at end of file
This diff is collapsed. Click to expand it.
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