1 win10系统,代码:
#!/usr/bin/python # -*- coding: UTF-8 -*- import time import tkinter as tk import tkinter.font as tf import webbrowser as web def save(): with open(di, mode=‘a‘, encoding=‘UTF-8‘) as fw: # 打开文件 txt = T1.get(‘1.0‘, ‘end‘)#全选 if len(txt.strip())>0: timenow = time.strftime("%Y-%m-%d %H:%M:%S ", time.localtime( int(time.time()))) txt = timenow + txt fw.write(txt) #写文件 T1.delete(‘1.0‘,‘end‘) #清空输入区 root.destroy()#退出 def show(): web.open(di) if __name__=="__main__": di = ‘F:/diary.txt‘#保存位置 root = tk.Tk() root.geometry(‘1000x600‘) root.title(‘日记-保存位置:‘+di) ft = tf.Font(family=‘仿宋‘, size=18) #设置字体 T1 =tk.Text(root, height=20,bd =5,font = ft) T1.pack(fill=‘x‘) tk.Button(root, text ="保存并退出", command = save).pack(side = ‘left‘) tk.Button(root, text ="查看历史", command = show).pack(side = ‘left‘) root.mainloop()
2 准备打包时发现pyinstaller仅支持到python3.7,于是卸了3.8,重装3.7,然后:
pip install pyinstaller
3 打包 在脚本所在目录中,执行
pyinstaller -F 工作日记.pyw
从输出中看到,在当前脚本目录下生成了dist目录,生成的EXE保存在其中。
原文地址:https://www.cnblogs.com/pu369/p/12672266.html
时间: 2024-10-03 14:00:32