I have created a gtkMenu using gtk.Menu()
, appended a couple of items and now I want to remove some menu item开发者_C百科s. How can I do that?
This should do the trick:
for i in menu.get_children():
menu.remove(i) # check here if you want to remove this child
gtk.Menu
inherits from gtk.Container
http://www.pygtk.org/docs/pygtk/class-gtkcontainer.html
EDIT
# 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?
Maybe using destroy()
could save some RAM:
menu.foreach(lambda child: child.destroy())
精彩评论