Eli
Eli

Reputation: 4926

gtk: find if a widget is from some type

I'm trying to find whether some widget in gtk is a ComboBox widget. The is word dont seem to work here

def set_entries_editable(self, bool, widget):
    '''define whether to enable/disable widget'''
        if widget is gtk.ComboBoxEntry:
            widget.set_sensitive(bool)
        else:
            widget.set_editable(bool)

Thanks!

Upvotes: 2

Views: 469

Answers (1)

falsetru
falsetru

Reputation: 368954

is is used to check object identity.

>>> a = [1, 2]
>>> b = [1, 2]
>>> a is b
False
>>> a is a
True

Use isinstance to check whether the object is instance of specific type:

>>> isinstance(a, list)
True

if isinstance(widget, gtk.ComboBoxEntry):

Upvotes: 4

Related Questions