0

after adding menu to GtkMenuButton it is not showing,tried different box to contain it(no use),anyone can say what i amdoing wrong?

    from gi.repository import Gtk


    class Window(Gtk.Window):
        def __init__(self):
            Gtk.Window.__init__(self)
            self.set_default_size(400, 200)
            self.set_default_geometry(400, 200)

            hb = Gtk.HeaderBar()
            hb.props.show_close_button = True
            hb.props.title = "Click me"
            self.set_titlebar(hb)

            box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
            pmenu = Gtk.Menu()
            pmenu.append(Gtk.MenuItem(label="lp"))
            pmenu.append(Gtk.MenuItem(label="pl"))
            mb = Gtk.MenuButton(popup=pmenu)
            box.add(mb)
            hb.pack_end(box)

    win = Window()
    win.connect("delete-event", Gtk.main_quit)
    win.show_all()
    Gtk.main()
Sam
  • 41
  • 1
  • 6

1 Answers1

0

By experience it seems that you're not making them visible:

from gi.repository import Gtk

class Window(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_default_size(400, 200)
        self.set_default_geometry(400, 200)

        hb = Gtk.HeaderBar()
        hb.props.show_close_button = True
        hb.props.title = "Click me"
        self.set_titlebar(hb)

        box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        pmenu = Gtk.Menu()
        for ml in ['lp', 'pl']:
            mi = Gtk.MenuItem(label=ml)
            mi.show()
            pmenu.append(mi)
        mb = Gtk.MenuButton(popup=pmenu)
        box.add(mb)
        hb.pack_end(box)

win = Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

Don't know why win.show_all doesn't show them too. Again, I say, I deduced that by experience.

See also:

Programatically add new menu items to menu item PyGObject?

Community
  • 1
  • 1
Havok
  • 5,776
  • 1
  • 35
  • 44