from gi.repository import GObject class Button(GObject.GObject): __gsignals__ = { "button-clicked": (GObject.SIGNAL_RUN_FIRST, None, ()) } def click(self): self.emit("button-clicked")
def print_message(): print("Button clicked!") button = Button() button.connect("button-clicked", print_message) button.click()Package library: GObject is a Python library, hence python-gobject package needs to be installed to use it.