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()

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM