在Gtk子菜单(item)上调用get_parent()
不会产生其父菜单,而是产生它扩展的对象。是否可以识别父菜单?
我需要一个比MCVE下面更复杂的菜单结构,以便切换上述菜单项的RadioMenuItem复选框。
menu = Gtk.Menu()
menu_item = Gtk.MenuItem('blah', 'blah')
menu_item.set_submenu(create_submenu())
menu.append(menu_item)
def create_submenu():
submenu = Gtk.Menu()
submenu_item = Gtk.MenuItem('blah', 'blah')
submenu.connect('activate', do_something)
submenu.append(submenu_item)
return submenu
def do_something(widget):
widget.get_parent().set_label('this is not the parent menu') # <--- refers to Gtk.Window, not our menu above