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()
复制代码

 

posted @   txwtech  阅读(81)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!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查询的等于大于符号是什么意思?
点击右上角即可分享
微信分享提示