1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import os
import tkinter as tk
from tkinter import filedialog
CURRENT_DIRECTORY = os.getcwd() # put directory of work !
def display():
"""Display file in current directory"""
options = {
'initialdir': CURRENT_DIRECTORY,
'title': 'Choose your file',
'filetypes': (("all files", "*.*"),)
}
name_file = filedialog.askopenfilename(**options)
print(name_file) # get name of file
master = tk.Tk()
button_choice = tk.Button(master, text='choice', command=display)
button_choice.pack()
master.mainloop() |
Partager