GTK Python MenuButton with GioAction weird behavior (second try)


I recently opened a topic that was closed without getting a valuable answer as my question was misunderstood and then not answered again after clarification…

I will try to explain the problem again in the hopes that this time it may be clearer…

An action with a shortcut (accelerator) in the example case <primary>p can successfully called via shortcut. But as soon as a PopoverMenu is opened and closed again, the previously working shortcut ceases to work.

What I found out already is, that if the Popover Menu has no items in it, this bug will not be triggered. But as soon as an item is added, even though it has nothing to do with the initially registered action and shortcut, said shortcut will no longer be working.

Here is the code again:

# -*- coding: utf-8 -*-
import gi

gi.require_version(namespace='Gtk', version='4.0')
from gi.repository import Gio, Gtk


class ExampleWindow(Gtk.ApplicationWindow):
    def __init__(self):
        self.set_title(title='Menu Shortcut Bug PoC')
        gio_menu =
        if TRIGGER_BUG:
        popover_menu = Gtk.PopoverMenu.new_from_model(gio_menu)
        headerbar =
        menu_button =

class ExampleApplication(Gtk.Application):
    def __init__(self):
        action ='poc', None)
        action.connect('activate', self.on_poc_action)
        self.set_accels_for_action(f'app.poc', ['<primary>p'])

    def do_activate(self):
        win = self.props.active_window
        if not win:
            win = ExampleWindow(application=self)

    def on_poc_action(self, action, param):
        print('Action activated')

if __name__ == '__main__':
    app = ExampleApplication()

If anyone runs into the same problem…

I got it to work through the use of action groups that i then registered on a widget.

Somehow by not registering an action directly on the application but via the action group the bug was not triggered. I’m still not sure why this was necessary in the first place, and if someone knows why, I would be interested in your explanation.

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