2
我有以下python(pygtk)程序。當我將鼠標移動到顯示的菜單上時,如果點擊托盤中的項目,複選框會被選中並立即取消選中。我使用Ubuntu 10.10或11.04。pygtk trayicon程序中的CheckMenuItem問題
#!/usr/bin/python
import gtk
import glib
import subprocess
import time
import sys
class StatusIcon:
def __init__(self):
self.statusicon = gtk.StatusIcon()
self.statusicon.set_from_stock(gtk.STOCK_HOME)
self.statusicon.connect("popup-menu", self.right_click_event)
def right_click_event(self, icon, button, time):
"""
We show a menu
"""
menu = gtk.Menu()
submenu = gtk.Menu()
menuitem = gtk.MenuItem("1")
submenu.append(menuitem)
menuitem = gtk.MenuItem("2")
submenu.append(menuitem)
lst = ["a","b","c"]
for item in lst:
newmenuitem = gtk.CheckMenuItem(str(item))
newmenuitem.set_submenu(submenu)
menu.append(newmenuitem)
# Now add all other menu stuff
menu.append(gtk.SeparatorMenuItem())
menuexit = gtk.CheckMenuItem("exit")
menuexit.connect("button-press-event", self.exit)
menu.append(menuexit)
# Show the menu
menu.show_all()
menu.popup(None, None, gtk.status_icon_position_menu, button, time, self.statusicon)
def exit(self, widget, event):
"""
Menu exit pressed
"""
if event.button == 1: #LEFT
print "terminate"
gtk.main_quit()
StatusIcon()
gtk.main()
PS:我試過用Ubuntu 10.10和11.04,在這兩種情況下它都有這種行爲! – 7asd23hasd 2011-06-17 18:16:42