I have created a treeview in my code, but I’m unable to retrieve the selected item and cell values, which would provide me with the row ID and cell information. Could you please guide me on how I can access these details?
import pandas as pd
from tkinter import *
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
style = ttk.Style(root)
style.theme_use("clam")
style.configure("Treeview.Heading", background="black", foreground="white")
def show_selection():
item = df_tree5.selection()[0]
cell = df_tree5.item(item)['values'][1] # not give me the data (cell value )
print(item)
print(cell)
df2=pd.read_csv('c:/erp/book2.csv')
df_list=list(df2.columns.values)
df_rset=df2.to_numpy().tolist()
df_tree5=ttk.Treeview(root,columns=df_list)
df_tree5.pack()
button5 = ttk.Button(root,text="Mostrar selección", command=show_selection)
button5.pack(side = BOTTOM)
for i in df_list:
df_tree5.column(i,width=100,anchor='c')
df_tree5.heading(i,text=i)
for dt in df_rset:
v=[r for r in dt]
df_tree5.insert('','end', values=v)
root.mainloop()
this is result
I006
132
this is result
I006
132
New contributor
not_a_stay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.