GtkMenuButton弹出菜单 [英] GtkMenuButton popups
本文介绍了GtkMenuButton弹出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将菜单添加到没有显示的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()
推荐答案
根据经验,您似乎没有使它们可见:
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不也显示它们。我再说一遍,我是根据经验推断出来的。
另见:
Programatically add new menu items to menu item PyGObject?
这篇关于GtkMenuButton弹出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文