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_w.title('www.plus2net.com')
my_font1=('times', 18, 'bold')
l1 = tk.Label(my_w,text='Upload File & read',width=30,font=my_font1)
l1.grid(row=1,column=1)
b1 = tk.Button(my_w, text='Upload File',
width=20,command = lambda:upload_file())
b1.grid(row=2,column=1)
trv=ttk.Treeview(my_w,selectmode='browse')
trv.grid(row=3,column=1,columnspan=4,padx=20,pady=20)
trv['show'] = 'tree'
def upload_file():
file = filedialog.askopenfilename(
filetypes=[("CSV files", ".csv")])
if file:
fob=open(file,'r')
i=0
for data in fob:
trv.insert("",'end',iid=i,text=data)
i=i+1
else:
print("No file chosen")
my_w.mainloop() # Keep the window open
if file:
in above code. The else part of the code will display the message. Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.