You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
9.6 KiB

from tkinter import *
import chardet
import datetime
import os
import tkinter.messagebox as ttk
from tkinter import Toplevel, Listbox, Scrollbar, END
from tkinter import filedialog
from tkinter import filedialog
desktop_path = os.path.join(os.path.expanduser("~"), 'Desktop')
def show_diary_calendar(date, content):
calendar_window = Toplevel(root)
calendar_window.title('日历 - 查看日记')
calendar_window.geometry("500x300") # 根据需要调整大小
listbox = Listbox(calendar_window, width=80)
listbox.insert(END, f"{date} - {content}")
listbox.pack(fill=BOTH, expand=True)
scroll = Scrollbar(calendar_window, command=listbox.yview)
scroll.pack(side=RIGHT, fill=Y)
listbox.config(yscrollcommand=scroll.set)
def helloCallBack6():
file_path = filedialog.askopenfilename(filetypes=[('Text Files', '*.txt')])
if file_path:
# 检测文件编码
with open(file_path, 'rb') as file:
result = chardet.detect(file.read())
encoding = result['encoding']
try:
with open(file_path, 'r', encoding=encoding) as file:
content = file.read()
date_str = os.path.splitext(os.path.basename(file_path))[0]
show_diary_calendar(date_str, content)
except (IOError, UnicodeDecodeError) as e:
ttk.showerror('错误', f"无法读取文件: {e}")
except Exception as e:
ttk.showerror('错误', f"处理文件时发生错误: {e}")
root=Tk()
root.title('日记')
root.resizable(width=False, height=False)
sw = root.winfo_screenwidth()
#得到屏幕宽度
sh = root.winfo_screenheight()
#得到屏幕高度
ww = 1000
wh = 600
#窗口宽高为100
x = (sw-ww) / 2
y = (sh-wh) / 2
root.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
#按键功能
def helloCallBack():
now = datetime.datetime.now()
a=now.year # 2022
b=now.month # 3
c=now.day # 20
e1.insert(0,a)
e2.insert(0,b)
e3.insert(0,c)
def helloCallBack1():
d=e1.get()
e=e2.get()
f=e3.get()
g=text1.get("0.0","end")
if d=='' or e=='' or f=='':
ttk.showerror('错误提示','警告:没有输入日期')
else:
name=d+'-'+e+'-'+f
full_path = name + '.txt' # 也可以创建一个.doc的word文档
file = open(full_path, 'w')
file.write(g)
file.close()
def jindu():
import tkinter as tk
import time
# 创建主窗口
window = tk.Tk()
window.title('保存')
sw = window.winfo_screenwidth()
#得到屏幕宽度
sh = window.winfo_screenheight()
#得到屏幕高度
ww = 400
wh = 100
#窗口宽高为100
x = (sw-ww) / 2
y = (sh-wh) / 2
window.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
window.overrideredirect(True)
# 设置下载进度条
tk.Label(window, text='加载进度:', ).place(x=0, y=40)
canvas = tk.Canvas(window, width=330, height=22, bg="#AAA")
canvas.place(x=60, y=40)
# 显示下载进度
def progress():
# 填充进度条
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="#00A")
x = 250 # 未知变量,可更改
n = 465 / x # 465是矩形填充满的次数
for i in range(x):
n = n + 465 / x
canvas.coords(fill_line, (0, 0, n, 60))
window.update()
time.sleep(0.008) # 控制进度条流动的速度
progress()
window.destroy()
window.mainloop()
jindu()
def helloCallBack2():
os._exit(0)
def helloCallBack3():
root1=Tk()
root1.title('查询日记')
sw = root1.winfo_screenwidth()
#得到屏幕宽度
sh = root1.winfo_screenheight()
#得到屏幕高度
ww = 450
wh = 100
#窗口宽高为100
x = (sw-ww) / 2
y = (sh-wh) / 2
root1.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
#文本加载
e01 = Entry(root1,width=10)
e02 = Entry(root1,width=10)
e03 = Entry(root1,width=10)
myLabel00=Label(root1,text='时间:',font=("楷体",18,"bold"),fg="#FFA500")
myLabel01=Label(root1,text='年:',font=("楷体",18))
myLabel02=Label(root1,text='月:',font=("楷体",18))
myLabel03=Label(root1,text='日:',font=("楷体",18))
#按键功能
def helloCallBack0():
a=e01.get()
b=e02.get()
c=e03.get()
name=a+'-'+b+'-'+c
full_path = name + '.txt' # 也可以创建一个.doc的word文档
def newone():
return os.path.isfile(full_path)
d=newone()
if d==False:
ttk.showerror('错误提示','警告:没有所选时间的日记')
elif d==True:
e=open(full_path)
top10=[]
for line in e.readlines():
top10.append(line)
e.close()
root2=Tk()
root2.title('日记')
root2.resizable(width=False, height=False)
sw = root2.winfo_screenwidth()
#得到屏幕宽度
sh = root2.winfo_screenheight()
#得到屏幕高度
ww = 1000
wh = 600
#窗口宽高为100
x = (sw-ww) / 2
y = (sh-wh) / 2
root2.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
#文本加载
text01 = Text(root2,height=20,font=("楷体",18),state=NORMAL)
text01.insert(0.0,top10)
text01.delete(0.0)
#文本显示
text01.grid(row=4,column=0)
#屏幕调用
root2.mainloop()
#文本显示
e01.grid(row=1,column=1)
e02.grid(row=1,column=3)
e03.grid(row=1,column=5)
myLabel00.grid(row=0,column=0)
myLabel01.grid(row=1,column=0)
myLabel02.grid(row=1,column=2)
myLabel03.grid(row=1,column=4)
#按键加载
btn1 = Button(root1,text='确定',bg='#AAA',fg="#000",command = helloCallBack0,font=("楷体",16))
#按键显示
btn1.grid(row=2,column=2)
#屏幕调用
root1.mainloop()
def helloCallBack4():
root3=Tk()
root3.title('删除日记')
sw = root3.winfo_screenwidth()
#得到屏幕宽度
sh = root3.winfo_screenheight()
#得到屏幕高度
ww = 450
wh = 100
#窗口宽高为100
x = (sw-ww) / 2
y = (sh-wh) / 2
root3.geometry("%dx%d+%d+%d" %(ww,wh,x,y))
#文本加载
e01 = Entry(root3,width=10)
e02 = Entry(root3,width=10)
e03 = Entry(root3,width=10)
myLabel00=Label(root3,text='时间:',font=("楷体",18,"bold"),fg="#FFA500")
myLabel01=Label(root3,text='年:',font=("楷体",18))
myLabel02=Label(root3,text='月:',font=("楷体",18))
myLabel03=Label(root3,text='日:',font=("楷体",18))
#按键功能
def helloCallBack01():
a=e01.get()
b=e02.get()
c=e03.get()
name=a+'-'+b+'-'+c
full_path = name + '.txt' # 也可以创建一个.doc的word文档
def newone():
return os.path.isfile(full_path)
d=newone()
if d==False:
ttk.showerror('错误提示','警告:没有所选时间的日记')
elif d==True:
os.remove(full_path)
ttk.showerror('提示','文件已成功删除')
#文本显示
e01.grid(row=1,column=1)
e02.grid(row=1,column=3)
e03.grid(row=1,column=5)
myLabel00.grid(row=0,column=0)
myLabel01.grid(row=1,column=0)
myLabel02.grid(row=1,column=2)
myLabel03.grid(row=1,column=4)
#按键加载
btn1 = Button(root3,text='确定',bg='#AAA',fg="#000",command = helloCallBack01,font=("楷体",16))
#按键显示
btn1.grid(row=2,column=2)
#屏幕调用
root3.mainloop()
#文本加载
e1 = Entry(root,width=10)
e2 = Entry(root,width=10)
e3 = Entry(root,width=10)
myLabel0=Label(root,text='时间:',font=("楷体",18,"bold"),fg="#FFA500")
myLabel1=Label(root,text='年:',font=("楷体",18))
myLabel2=Label(root,text='月:',font=("楷体",18))
myLabel3=Label(root,text='日:',font=("楷体",18))
myLabel4=Label(root,text='日记部分:',font=("楷体",18))
text1 = Text(root,bg='#000',height=20,fg="#FFF",font=("楷体",18))
#按键加载
btn1 = Button(root,text='自动填充',bg='#AAA',fg="#0FF",command = helloCallBack,font=("楷体",16))
btn2 = Button(root,text='保存日记',bg='#00F',fg="#000",command = helloCallBack1,font=("楷体",16,"bold"))
btn3 = Button(root,text='退出日记',bg='#F00',fg="#000",command = helloCallBack2,font=("楷体",16,"bold"))
btn4 = Button(root,text='查询日记',bg='#0F0',fg="#000",command = helloCallBack3,font=("楷体",16,"bold"))
btn5 = Button(root,text='删除日记',bg='#F00',fg="#000",command = helloCallBack4,font=("楷体",16,"bold"))
btn6 = Button(root, text='查看日记日历',bg='#F00',fg="#000", command=helloCallBack6,font=("楷体",16,"bold"))
#文本显示
e1.grid(row=1,column=2)
e2.grid(row=1,column=4)
e3.grid(row=1,column=6)
myLabel0.grid(row=0,column=0)
myLabel1.grid(row=1,column=1)
myLabel2.grid(row=1,column=3)
myLabel3.grid(row=1,column=5)
myLabel4.grid(row=3,column=0)
text1.grid(row=4,column=0,columnspan=100)
#按键显示
btn1.grid(row=1,column=7)
btn2.grid(row=3,column=1)
btn3.grid(row=2,column=0)
btn4.grid(row=2,column=1)
btn5.grid(row=2,column=2)
btn6.grid(row=2,column=3)
#屏幕调用
root.mainloop()