Python Treeview get_selected()

Python Treeview get_selected()

There is a tiny detail about using this function. this function works only on SINGLE mode. For example; you need to select all rows

selection.set_mode(Gtk.SelectionMode.MULTIPLE) selection.select_all()

then you need to get a value

model, treeiter = selection.get_selected() if treeiter != None:   value = str(model[treeiter][0])

but it crashed and give you this error : Runtime error::gtk_tree_selection_get_selected: assertion `selection->type != GTK_SELECTION_MULTIPLE’ failed

* *

so you must change your code like this:

selection.set_mode(Gtk.SelectionMode.MULTIPLE) selection.select_all()

……………………….

selection.set_mode(Gtk.SelectionMode.SINGLE) selection.unselect_all()

and the other part:

#be sure if it is on SINGLE mode if selection.get_mode()==Gtk.SelectionMode.SINGLE:    model, treeiter = selection.get_selected()       if treeiter != None:          name = str(model[treeiter][0])