The activate event does nothing in MenuButton pygobject?

I’m trying to use MenuButton’s activate event to do something in pygobject, but my code is not executed. I’m wondering if I’m missing something.

gtk4 version is 4.12.5-1.fc39 in Fedora 39
pygobject version is 3.48.1 from pypi

def button_activated(_button):
    print("Button activated")

btn = Gtk.MenuButton(label="test")
btn.connect("activate", button_activated)

The “activate” signal is emitted when a widget is activated—the user pressed Return, or something called Gtk.Widget.activate().

Gotcha, my expectation of a click emitting the activate signal was wrong then. I’m going to use ‘notify::active’ now instead… I just wanted to do something when the popup opens.

Quick question. SpinButton only has the ‘activate’ signal since GTK 4.14. How would I do the “do something when pressing enter” before that version?

You’d have to add an EventControllerKey, add set it to handle the capture phase, so you get the Enter key before the widget.

Cool, I’ll try that. Hey, thank you. :wink:

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