Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7871233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:50:41+00:00 2026-06-03T01:50:41+00:00

In my small PyGObject/GTK3 application I try to create a (sub-)menu that consists of

  • 0

In my small PyGObject/GTK3 application I try to create a (sub-)menu that consists of RadioMenuItems.

I create the menu as follows in the main window’s __init__:

menu_item = None
self.menu = Gtk.Menu()
self.menu_items = {}
for i in range(1,5):
   menu_item = Gtk.RadioMenuItem(menu_item)
   menu_item.set_label(str(i))
   self.menu_items[i] = menu_item
   self.menu.append(self.menu_items[i])
   self.menu_items[i].connect("activate",
                        self.on_menu_select,
                        i)
   self.menu_items[i].show()

and then show it in the button_press_event handler using

def button_press(self, widget, event, data=None):
    for i in range(1,5):
        self.menu_items[i].set_active(False)
    self.menu_items[2].set_active(True)
    self.menu.popup(None, None, None, None,
                            event.button, event.time)

When I open the menu for the first time, menu item “2” is correctly the only one selected.
When I then – for example – choose menu item “3” and open the menu again, both menu items 2 and 3 are selected. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:50:42+00:00Added an answer on June 3, 2026 at 1:50 am

    You have to put the radio menu items in a group with each other, or else they won’t know to deselect themselves when another one is selected:

    self.menu = Gtk.Menu()
    self.menu_items = list()
    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)
    

    Note that this line selects item number 2, you don’t have to do it yourself, so your button press handler can simply be:

    def button_press(self, widget, event, data=None):
        self.menu.popup(None, None, None, None,
                        event.button, event.time)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small application that uses a DrawingArea to draw a simple map
A small - little question. I have seen many application having buttons like following.
Small problem with my query here: CREATE VIEW rental_view AS SELECT m.movie_id, movie_name, co.copy_id,
My small windows form application has two radio buttons, and initially neither is checked.
A small utility of mine that I made for personal use (written in C++)
A small number of our users are experiencing an error when they try to
I wrote a very small application, which access the Remote Power Shell of Exchanger
I'm trying to create a small app for users to have contacts. I'm using
Small problem here with an MVC app that I'm not sure how to figure
I have written a small Asp.net application using Entity Framework. A Stored Procedure accepts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.