我使用gtk.Menu()
创建了一个gtkMenu,附加了几个项目,现在我想删除一些菜单项。我怎么能这样做?
答案 0 :(得分:8)
这应该可以解决问题:
for i in menu.get_children():
menu.remove(i) # check here if you want to remove this child
gtk.Menu
继承自gtk.Container
http://www.pygtk.org/docs/pygtk/class-gtkcontainer.html
编辑
# First remove all old timer menu items from the gtkMenu
if TimerAppIndicator.menuList:
for i in TimerAppIndicator.menuList:
self.menu.remove(TimerAppIndicator.menuList[j])
j+=1 <---- 1) j isn't declared here
2) you will skip items why not just self.menu.remove(i)
you're already iterating over the menu items
# Delete all timer menu items from the list storing them
del TimerAppIndicator.menuList[:]
j=0 <--------- shouldn't this be before j+=1?
答案 1 :(得分:0)
也许使用 destroy()
可以节省一些 RAM:
menu.foreach(lambda child: child.destroy())