将菜单添加到GtkMenuButton后它没有显示,尝试使用不同的框来包含它(没用),任何人都能说出我错的是什么?
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()
答案 0 :(得分:0)
根据经验,您似乎并没有将它们显示出来:
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()
不知道为什么win.show_all也没有显示出来。我再次说,我根据经验推断出这一点。
另见: