How to make the window opening when you click on the TreeView Tkinter string? That is, the user clicks on the string with the data they need and the new window opens, where the same data as in this line + everything else is from the database. How to display data from the database into a separate window I know, but how to get data from the selected line in TreeView in any way I do not understand. Tell me, please
Answer 1, Authority 100%
Let’s say we need to choose some action when choosing a row in the tree, while you need to access the data in the selected row. To response to the selection of the line, you need to be attached to the & lt; & lt; TreeViewSelect & GT; & GT;
Tree (in principle, you can use another event, for example, double click on the left mouse button – & lt; Double-Button-1 & gt ;
). Further through the Selection
method, you need to get a list of identified elements. Further on ID, you can get the values in the string.
def one_select (event):
# output text ID of all selected rows
# (there may be several them if there was no selectmode = 'browse' when creating a tree)
Print (TreeView.Selection ())
# If you are tied not to an Event & lt; & lt; TreeViewSelect & GT; & gt;
# then you need to check that something is chosen generally:
If not treeview.selection ():
Return.
# Get the ID of the first selected item
selected_item = TreeView.selection () [0]
# Get values in highlighted row
Values = TreeView.Item (Selected_Item, Option = "Values")
Print (Values)
TreeView.bind ('& LT; & LT; TreeViewSelect & GT; & GT;', On_Select)