如何在PyGTK中的TreeView中捕获选定的行和列? [英] How do I capture the selected row and column in a TreeView in PyGTK?

查看:188
本文介绍了如何在PyGTK中的TreeView中捕获选定的行和列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 gtk.TreeView 创建的表。我想知道用户选择了哪一行和哪一列。这怎么可能?

解决方案

您想要的行的方法是gtk.TreeSelection.get_selected或gtk.TreeSelection.get_selected_rows,取决于您选择的选择方法(SELECTION_SINGLE,SELECTION_MULTIPLE或SELECTION_BROWSE)。

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



对于使用gtk.TreeView.get_path_at_pos

的列,您可以使用

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



但是您需要提供比这种方法更多的功能它的坐标首先。这可能会让你更深入地了解它:



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



get_path_at_pos将返回路径和列,所以如果你确实需要知道被点击的列,这可能是一种方法。所以关键在于上面例子中列出的按钮事件和PyGTK中的 http://www.pygtk.org/docs/pygtk/class-gdkevent.html


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

这篇关于如何在PyGTK中的TreeView中捕获选定的行和列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆