开发者

How to remove an item from a gtkMenu?

开发者 https://www.devze.com 2023-01-26 19:16 出处:网络
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:

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())

0

精彩评论

暂无评论...
验证码 换一张
取 消