Search code examples
pythongtkpygtkgtktreeview

Gtk.Treeview get current row index in Python


How to get index of current selected row in Gtk.TreeView in Python ?


Solution

  • You can call gtk.TreeView.get_selection to get the current selection (gtk.TreeSelection). You can then call gtk.TreeSelection.get_selected to get:

    a 2-tuple containing a reference to the gtk.TreeModel and a gtk.TreeIter pointing to the currently selected node.

    The iter can be used on a gtk.TreeModel (which is obtained by calling gtk.TreeView.get_model. You can then use gtk.TreeModel.get_value to get any of the column values of the node at that position in the tree.