1from tkinter import filedialog
2
3 # Where it open to. # What the window is called. # What file types the user can choose between. first one is the defualt. (("what ever", "*.format"), ("what ever 2", "*.format2"))
4filedialog.askopenfilename(initialdir=os.path.normpath("C://"), title="Example", filetypes =(("PNG", "*.png"),("JPG", "*.jpg"),("All Files","*.*")))
1from tkinter import filedialog
2
3 # Where it open to. # What the window is called.
4folder = filedialog.askdirectory(initialdir=os.path.normpath("C://"), title="Example")
1def open_file():
2 file = askopenfile(mode='r', filetypes=[
3 ('Text files', '*.txt'), ('CSV Files', '*.csv')])
4 if file is not None:
5 print(file.name.split("/")[-1]) # this will print the file name
6
7btn = Button(root, text='Open', command=lambda: open_file())
8btn.pack(side=TOP, pady=10)