Search code examples
pythonpython-3.xgtk3glade

How to access to widgets properties in a Gtk+ 3 / Glade / Python 3 project


I use the classical code example :

from gi.repository import Gtk

class Handler():

    def onDeleteWindow(self, *args):
        Gtk.main_quit(*args)

    def on_button1_clicked(self, button):
        print("Hello World!")

builder = Gtk.Builder()
builder.add_from_file("D:/temp/test1.glade")
builder.connect_signals(Handler())

window = builder.get_object("window1")
window.show_all()

Gtk.main()

And all is OK. But :

  • How to change a widget property in event. Like change the button1 label on click on it. Mainly because in the event is in Handler which does'nt see window ?
  • Where/how to have all the Python/Gtk informations about widgets, like widgets properties names (ie : what is the label property of a GtkButton ?) ?

Solution

  • Where/how to have all the Python/Gtk informations about widgets, like widgets properties names?

    https://lazka.github.io/pgi-docs/#Gtk-3.0

    How to change a widget property in event. Like change the button1 label on click on it.

    button.set_label()
    

    https://lazka.github.io/pgi-docs/#Gtk-3.0/classes/Button.html#Gtk.Button.set_label