tkinter 保存文件和打开文件

https://pythonguides.com/category/python-tutorials/python-tkinter/

 

 

 

 

 

 

 

 

 

 

 

from tkinter import *

from tkinter.filedialog import asksaveasfile
from tkinter import filedialog

ws = Tk()
ws.geometry('200x200')
ws.title("Python Guides")


def save():
    Files = [('All Files', '*.*'),
             ('Python Files', '*.py'),
             ('Text Document', '*.txt')]
    file = asksaveasfile(filetypes=Files, defaultextension=Files)


def get_file_path():
    global file_path1
    file_path1 = filedialog.askopenfilename(title="Select A File", filetypes=(
        ("Python files", "*.png"), ("mp4", "*.mp4"), ("wmv", "*.wmv"), ("avi", "*.avi")))
    l1 = Label(ws, text="File path: " + file_path1).pack()


button = Button(ws, text='Save', command=lambda: save())
button.pack(side=TOP, pady=20)
button = Button(ws, text="openfile", command=get_file_path).pack(pady=10)

ws.mainloop()

  

posted @ 2021-11-17 19:25  linbo.yang  阅读(1043)  评论(0编辑  收藏  举报