python tkinter 简单编辑器demo打开与保存文件
python tkinter 简单编辑器demo打开与保存文件
def load_file(): with open(filename.get()) as file: contents.delete('1.0', END) contents.insert(INSERT, file.read()) def save_file(): with open(filename.get(),'w') as file: file.write(contents.get('1.0',END))
if __name__ == '__main__': print_hi('good day') main() product_code = func_switch_case("bag") print(f"bag的产品编号:{product_code}") product_code = func_switch_case2("pencil") print(f"case2_pencil的产品编号:{product_code}") from tkinter import * from tkinter.scrolledtext import ScrolledText top = Tk() top.title('简单编辑器') contents = ScrolledText() #编辑框 contents.pack(side=BOTTOM, expand= True, fill=BOTH) Label(text='路径:').pack(side=LEFT) import tkinter as aa def_str = aa.StringVar(value='D:\\file_test.txt') filename = Entry(textvariable=def_str, background='green') #路径输入框 D:\file_test.txt filename.pack(side=LEFT, expand=True, fill=X) Button(text='打开', command=load_file).pack(side=LEFT) Button(text ='保存', command=save_file).pack(side=LEFT) mainloop()
欢迎讨论,相互学习。
cdtxw@foxmail.com
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
2022-12-28 qt 调用窗口 mainwindow.cpp:9:78: error: incomplete type 'QDialog' named in nested name specifier qwindowdefs.h:55:7: note: forward declaration of 'QDialog'
2022-12-28 System.InvalidOperationException:“线程间操作无效: 从不是创建控件“Form1”的线程访问它。”
2021-12-28 c# linq查询的等于大于符号是什么意思?