Tkinter filedialog to display Treeview

Displaying data in Treeview by using Tkinter filedialog to show file browser to upload & read file
We will use one Treeview to display the data of the Filedialog uploaded file ( after reading ) inside the same window.
Display data of uploaded file
import tkinter as tk
from tkinter import ttk,filedialog
from tkinter.filedialog import askopenfile
my_w = tk.Tk()
my_w.geometry("400x300")  # Size of the window 
my_font1=('times', 18, 'bold')
l1 = tk.Label(my_w,text='Upload File & read',width=30,font=my_font1)  
b1 = tk.Button(my_w, text='Upload File', 
   width=20,command = lambda:upload_file())
trv['show'] = 'tree'
def upload_file():
    file = filedialog.askopenfilename(
        filetypes=[("CSV files", ".csv")])
    if file:        
        for data in fob:
        print("No file chosen")
my_w.mainloop()  # Keep the window open

When user cancels the file window

After opening the file browser the user may use the cancel button to close the operation, to handle this we have added the if file: in above code. The else part of the code will display the message.

Tkitner Treeview to get Parent Child nodes and display data in hierarchical order

Tkinter filedialog.askopenfile() Upload and display image file
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer