I have created a gtkMenu using gtk.Menu()
, appended a couple of items and now I want to remove some menu items. 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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With