Python Tkinter – File Chooser Example

Hello everyone, In this example, you will learn how to bring file chooser using Tkinter in Python. The example program has been tested and shared in the same post.

Example Program

import tkinter as tk
from tkinter.filedialog import askopenfilename


# defining open_file_chooser function
def open_file_chooser():
    filename = askopenfilename()
    print("You have selected : %s" % filename)


# creating an instance of Tk
root = tk.Tk()
root.title("Example")

# Button : Open
open = tk.Button(root, text = "Open", command = open_file_chooser)
open.pack()

# Starting the Application
root.mainloop()

Output

You have selected : C:/Users/Dinesh/Desktop/example.jpg