[更新]用Python做一个日记软件
新版本更新啦!祝各位新年快乐!
第一版本传送门
更新要点:
1.背景图片更新
2.修改了主页无法访问的Bug
3.修改了一些由于大意导致的错误
增加功能:
1.能显示已经写日记的天数
核心代码:(写日记部分)
def write():
number = 1
num = 0
for _ in range(int(number)):
num += 1
res = requests.get('http://v1.hitokoto.cn')
data = json.loads(res.text)
beautiful = data['hitokoto']
if num % 20 == 0:
time.sleep(5)
else:
time.sleep(2)
text = beautiful
first = tk.Tk()
first.title('BookBook -' + text)
first.geometry('500x220')
first.iconbitmap('pic.ico')
menuBar = tk.Menu(first)
filemenu = Menu(menuBar, tearoff=0)
menuBar.add_cascade(label="文件",menu=filemenu)
filemenu.add_command(label='主页', command=zhu)
filemenu.add_command(label='退出',command=ex)
filemenu.add_separator()
filemenu.add_command(label='关于',command = abo)
wr = Menu(menuBar, tearoff=0)
menuBar.add_cascade(label="查看",menu=wr)
wr.add_command(label='全部日记',command = look)
setting = Menu(menuBar, tearoff=0)
menuBar.add_cascade(label="设置",menu=setting)
setting.add_command(label='设置',command = pu)
first.config(menu=menuBar)
photo = tk.PhotoImage(file="背景.png")
theLabel = tk.Label(first,image = photo)
theLabel.grid()
monty = tk.LabelFrame(text='写日记')
monty.grid(column=0, row=0, padx=20, pady=20)
ttk.Label(monty, text="心情:").grid(column=0, row=0, sticky='W')
name = tk.StringVar()
nameEntered = tk.Entry(monty, width=30, textvariable=name)
nameEntered.grid(column=1, row=0, sticky='W')
ttk.Label(monty, text="我想说:").grid(column=0, row=2, sticky='W')
ad = tk.StringVar()
adEntered = tk.Entry(monty, width=30, textvariable=ad)
adEntered.grid(column=1, row=2, sticky='W')
nowTime = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
def ok():
with open('diary.txt', 'a+') as f:
f.write(nowTime + '\n' + nameEntered.get() + '\n' + adEntered.get() + '\n')
with open('one.txt','a+') as f:
f.write(adEntered.get() + '\n')
with open('number.txt','a+') as f:
f.write('1')
mBox.showwarning('提示', '已完成!')
action = ttk.Button(monty, text="完成", width=10, command=ok)
action.grid(column=3, row=3, rowspan=2, ipady=7)
ac = ttk.Button(monty, text="退出", width=10, command=ex)
ac.grid(column=5, row=3, rowspan=2, ipady=7)
first.mainloop() 谢谢大佬!{:10_257:} 正经人谁写日记啊 谢谢
页:
[1]