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

随声附和 提交于 2019-12-24 12:35:20

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/14352760/how-do-i-capture-the-selected-row-and-column-in-a-treeview-in-pygtk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!