简体   繁体   中英

How can I group RadioMenuItem? (PyGtk)

That's the question.

I'm making an indicator for Ubuntu, all works fine, but... When I try to set two "RadioMenuItem" they are totally independent. I can check both.

The items:

item_first = gtk.RadioMenuItem('First Radio')
item_first.connect('activate', first_radio)
menu.append(item_first)

item_second = gtk.RadioMenuItem('Second Radio')
item_second.connect('activate', second_radio)
menu.append(item_second)

Should I use a container or something like this? Please, help me.

Try this,

self.menu = Gtk.Menu()
self.menu_items = list("First Radio","Second Radio")
group = []
for i in range(1,5):
    menu_item = Gtk.RadioMenuItem.new_with_label(group, str(i))
    group = menu_item.get_group()
    self.menu_items[i] = menu_item
    self.menu.append(menu_item)
    menu_item.connect("activate", self.on_menu_select, i)
    menu_item.show()

self.menu_items[2].set_active(True)

That's an old one, I know. However the solution is as following:

item_first = gtk.RadioMenuItem('First Radio')
item_first.connect('activate', first_radio)
menu.append(item_first)

item_second = gtk.RadioMenuItem('Second Radio', group=item_first) # <-- note group
item_second.connect('activate', second_radio)
menu.append(item_second)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM