简体   繁体   中英

How do I capture the selected row and column in a TreeView in PyGTK?

I have a table created using gtk.TreeView . I want to know which row and column is selected by the user. How is this possible?

The methods for the rows you want are gtk.TreeSelection.get_selected or gtk.TreeSelection.get_selected_rows, depending on the selection method you have chosen (SELECTION_SINGLE, SELECTION_MULTIPLE OR SELECTION_BROWSE).

http://www.pygtk.org/docs/pygtk/class-gtktreeselection.html#method-gtktreeselection--get-selected

For columns you would work with gtk.TreeView.get_path_at_pos

http://pygtk.org/docs/pygtk/class-gtktreeview.html#method-gtktreeview--get-path-at-pos

But you will need more than this method alone, since you need to supply the coordinates for it first. This might give a you a deeper insight in it:

http://www.gtkforums.com/viewtopic.php?f=3&t=2645

get_path_at_pos will return both path and column, so this is probably the method to go for if you really need to know the column that was clicked. So the key to this remains the button press event as listed in the example above and for PyGTK in http://www.pygtk.org/docs/pygtk/class-gdkevent.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM