Friday, October 28, 2022

[FIXED] How to check if a Gtk.ListStore is empty in Python?

Issue

I want to check with an if statement if my Gtk.ListStore is empty. This means, there are no rows on it. I am using Gtk+3 and Python 3.5.2. Thanks.


Solution

Gtk.ListStore implements the interface Gtk.TreeModel. You can use get_iter_first to check if the store it's empty.

With python, you can also use the len() method to check the size of the store, if 0 (zero), then it's empty. eg:

if (len(store)==0):
   #Empty
   ...
else:
   #NotEmpty
   ...

The size of the store equals the number of rows:

nrows=len(store)


Answered By - José Fonte
Answer Checked By - Willingham (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.