我认为你使用了错误的方法。我会使用
RadioMenuItem
。然后,如果radiomenuitem的活动状态为False,我将阻止“更改”代码。这将导致如下结果:
def build_menu():
menu = gtk.Menu()
item_suspend = gtk.RadioMenuItem('Set lid to suspend')
item_suspend.connect('activate', set_lid_suspend)
menu.append(item_suspend)
item_nothing = gtk.RadioMenuItem('Set lid to nothing')
item_nothing.connect('activate', set_lid_nothing)
menu.append(item_nothing)
item_suspend.join_group(item_nothing)
menu.show_all()
return menu
def set_lid_suspend(menuItem):
if menuItem.get_active() == False:
return
call([os.path.join(__location__, "setLidSuspend.sh")])
noot.update("<b>Set lid to suspend.</b>", "", None)
noot.show()
def set_lid_nothing(menuItem):
if menuItem.get_active() == False:
return
call([os.path.join(__location__, "setLidNothing.sh")])
noot.update("<b>Set lid to nothing.</b>", "", None)
noot.show()
因为你发布了不完整的代码,所以我不能确定测试结果。试试看,让我知道。