我在gtk.MenuBar
下面有一个普通的框架。每当鼠标悬停在一个项目上,并且该子菜单由于失去焦点而被隐藏时,在重新访问该子菜单时,所有项目都将丢失。
预期的行为是,每次使用指针激活“文件”、“游戏”和“帮助”时,菜单项会按照添加到菜单和子菜单的顺序重新出现。
这种感知错误的原因是什么?是否gtk.MenuBar
需要更多“实施”才能正常运行?
不想要的结果如下图所示:
#!/usr/bin/python
import gtk
def callbackz(*argv):
print str(*argv)
class ChessMenuBar(gtk.MenuBar):
def __init__(self):
super(ChessMenuBar, self).__init__()
menu_file = gtk.Menu()
item_open = gtk.MenuItem('Open')
item_save = gtk.MenuItem('Save')
item_quit = gtk.MenuItem('Quit')
menu_file.append(item_open)
menu_file.append(item_save)
menu_file.append(item_quit)
menu_game = gtk.Menu()
item_newg = gtk.MenuItem('Star New Game')
menu_game.append(item_newg)
menu_help = gtk.Menu()
item_help = gtk.MenuItem('Help')
menu_help.append(item_help)
# -- main categories
item_file = gtk.MenuItem('File')
item_game = gtk.MenuItem('Game')
item_help = gtk.MenuItem('Help')
item_file.set_submenu(menu_file)
item_game.set_submenu(menu_game)
item_help.set_submenu(menu_help)
self.append(item_file)
self.append(item_game)
self.append(item_help)
for _ in [ item_file, item_game, item_help,
item_help, item_newg, item_open,
item_quit, item_save]:
_.connect('activate', callbackz)
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
self.set_title("Simple menu")
self.set_size_request(250, 200)
self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(6400, 6400, 6440))
self.set_position(gtk.WIN_POS_CENTER)
mb = ChessMenuBar()
vbox = gtk.VBox(False, 2)
vbox.pack_start(mb, False, False, 0)
self.add(vbox)
self.connect("destroy", gtk.main_quit)
self.show_all()
PyApp()
gtk.main()
$ winPython --version
Python 2.7.3
$ cat /cygdrive/c/Python27/Lib/site-packages/gtk-2.0/pygtk-2.22.0-py2.7.egg-info
Metadata-Version: 1.1
Name: pygtk
Version: 2.22.0
( abbreviated )
Platform: MS Windows
Requires: pycairo (>=1.0.2)
Requires: pygobject (>=2.21.3)
Provides: p
Provides: y
Provides: g
Provides: t
Provides: k