tkinter filedialog filename code example
Example 1: python tkinter filedialog
from tkinter import filedialog
filedialog.askopenfilename(initialdir=os.path.normpath("C://"), title="Example", filetypes =(("PNG", "*.png"),("JPG", "*.jpg"),("All Files","*.*")))
Example 2: python tkinter filedialog folder
from tkinter import filedialog
folder = filedialog.askdirectory(initialdir=os.path.normpath("C://"), title="Example")
Example 3: tkinter filedialog filename
def open_file():
file = askopenfile(mode='r', filetypes=[
('Text files', '*.txt'), ('CSV Files', '*.csv')])
if file is not None:
print(file.name.split("/")[-1])
btn = Button(root, text='Open', command=lambda: open_file())
btn.pack(side=TOP, pady=10)