How do I create an Import File Button with Tkinter?

后端 未结 1 1353
死守一世寂寞
死守一世寂寞 2021-01-17 07:09

So you know how when you use Notepad (on Windows), for example, and you want to open an old file? You click file, then open, then a file dialog opens ups and you can select

1条回答
  •  别那么骄傲
    2021-01-17 07:34

    import tkinter as tk
    from tkinter import filedialog
    
    def UploadAction(event=None):
        filename = filedialog.askopenfilename()
        print('Selected:', filename)
    
    root = tk.Tk()
    button = tk.Button(root, text='Open', command=UploadAction)
    button.pack()
    
    root.mainloop()
    

    0 讨论(0)
提交回复
热议问题