Python GTK+ 3: Accessing MenuButton from Popover?

Viewed 54

I'm new to GTK+ programming, and I want to do the following: I have a MenuButton with a Popover. The Popover has a Button inside. After I click the inside button, I want to be able to access the MenuButton somehow. Here is an example of what I mean:

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk


class PopoverWindow(Gtk.Window):
    def __init__(self):
        super().__init__(title="my window")

        outerbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(outerbox)

        self.popover = Gtk.Popover()
        
        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.button = Gtk.Button(label="Item 1")
        self.button.connect('clicked', self.on_button_clicked)
        vbox.pack_start(self.button, False, True, 10)
        vbox.show_all()
        self.popover.add(vbox)
        self.popover.set_position(Gtk.PositionType.BOTTOM)

        menu_button = Gtk.MenuButton(label="Click Me", popover=self.popover)
        outerbox.pack_start(menu_button, False, True, 0)

    def on_button_clicked(self, button):
        # how to access the menu_button?

win = PopoverWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()

Inside on_button_clicked, I don't know how to access menu_button anymore. I can't call button.get_parent(), button.get_parent().get_parent(), etc., because the popover is not a child of menu_button.

I should also say that changing menu_button to self.menu_button is not an option for me. Any help would be appreciated!

1 Answers
Related