如何从gtkMenu中删除项目?

Ing*_*ngo 7 python pygtk

我创建了一个gtkMenu使用gtk.Menu(),附加了几个项目,现在我想删除一些菜单项.我怎样才能做到这一点?

Ivo*_*zel 8

这应该做的伎俩:

for i in menu.get_children():
    menu.remove(i) # check here if you want to remove this child
Run Code Online (Sandbox Code Playgroud)

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?
Run Code Online (Sandbox Code Playgroud)