First
Then the code:
Import ttkfrom Tkinter Import *root = Tk () tree = TTK. Treeview (Root, columns= (' col1 ', ' col2 ', ' col3 '))
Tree.column (' col1 ', width=100, anchor= ' center ') tree.column (' col2 ', width=100, anchor= ' center ') tree.column (' Col3 ', width=100, anchor= ' center ') tree.heading (' col1 ', text= ' col1 ') tree.heading (' col2 ', text= ' col2 ') tree.heading (' Col3 ', text= ' col3 ')
def ondbclick (event): item = tree.selection () [0] print "You clicked on", Tree.item (item, "values") for I in R Ange: Tree.insert ("', i,values= (' A ' +str (i), ' B ' +str (i), ' C ' +str (i))" Tree.bind ("<Double-1>", Ondbclick) Tree.pack () Root.mainloop ()
Say something:
- TTK looks like python comes with it.
- The TreeView is essentially a tree.
- The above is the weakening version, which is what we usually see in the ListView
- Support for event binding, using Tree.bind mates Tree.item and Tree.selection (), you can write code for events such as clicking, double-clicking, and so on.
Python tkinter using the TreeView to achieve a ListView effect