Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an item from a gtkMenu?

Tags:

python

pygtk

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?

like image 681
Ingo Avatar asked Nov 23 '10 17:11

Ingo


1 Answers

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?
like image 144
Ivo Wetzel Avatar answered Oct 22 '22 12:10

Ivo Wetzel