Askopenfilename
filename2 = filedialog.askopenfilename(title = "Select file",filetypes = (("Excel files", ".xlsx .xls"),))
Fair Frog
filename2 = filedialog.askopenfilename(title = "Select file",filetypes = (("Excel files", ".xlsx .xls"),))
import tkinter as tk
from tkinter import ttk
from tkinter import filedialog as fd
root = tk.Tk()
def select_file():
filetypes = (
('text files', '*.txt'),
('All files', '*.*')
)
filename = fd.askopenfilename(
title='Open a file',
initialdir='/',
filetypes=filetypes)
showinfo(
title='Selected File',
message=filename
)
# open button
open_button = ttk.Button(
root,
text='Open a File',
command=select_file
)
open_button.pack(expand=True)
root.mainloop()