How should we do widget type comparisons?

I have a gtk builder object, and I’m iterating over widgets and deciding what to do with them based on their type. How do I do this type comparison? If I use:

this_type = type( this_widget )

… I get a gi.overrides.Gtk.Window ( for example ) if this_widget was a Gtk.Window. I just want to be able to go:

if this_type == 'Gtk.Window':
    # do stuff

That sounds horrific…

With isinstance():

if isinstance(this_widget, Gtk.Window):
    print(f"{this_widget} is a window")
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.