Gtk.RadioMenuItem
Gtk.RadioMenuItem — A choice from multiple check menu items
Object Hierarchy:
GObject
╰── GInitiallyUnowned
╰── Gtk.Widget
╰── Gtk.Container
╰── Gtk.Bin
╰── Gtk.MenuItem
╰── Gtk.CheckMenuItem
╰── Gtk.RadioMenuItem
See also:
Gtk.MenuItem, Gtk.CheckMenuItem
Functions:
- new
(group:list=None) -> Gtk.Widget
- new_with_label
(group:list=None, label:str) -> Gtk.Widget
- new_with_mnemonic
(group:list=None, label:str) -> Gtk.Widget
- new_from_widget
(group:Gtk.RadioMenuItem=None) -> Gtk.Widget
- new_with_label_from_widget
(group:Gtk.RadioMenuItem=None, label:str=None) -> Gtk.Widget
- new_with_mnemonic_from_widget
(group:Gtk.RadioMenuItem=None, label:str=None) -> Gtk.Widget
- set_group
(self, group:list=None)
- get_group
(self) -> list
- join_group
(self, group_source:Gtk.RadioMenuItem=None)
Description:
A radio menu item is a check menu item that belongs to a group. At each instant exactly one of the radio menu items from a group is selected.
The group list does not need to be freed, as each Gtk.RadioMenuItem
will remove itself and its list item when it is destroyed.
The correct way to create a group of radio menu items is approximatively.
How to create a group of radio menu items.
menuitem = Gtk.MenuItem(label="RadioMenuItem")
menubar.append(menuitem)
menu = Gtk.Menu()
menuitem.set_submenu(menu)
radiomenuitem1 = Gtk.RadioMenuItem(label="RadioMenuItem 1")
radiomenuitem1.set_active(True)
menu.append(radiomenuitem1)
radiomenuitem2 = Gtk.RadioMenuItem(label="RadioMenuItem 2", group=radiomenuitem1)
menu.append(radiomenuitem2)
Function Details:
new()
new (group:list=None) -> Gtk.Widget
Creates a new Gtk.RadioMenuItem
.
- Returns: a new Gtk.RadioMenuItem
new_with_label()
new_with_label (group:list=None, label:str) -> Gtk.Widget
Creates a new Gtk.RadioMenuItem
whose child is a simple Gtk.Label
.
- Returns:
A new
Gtk.RadioMenuItem
.
new_with_mnemonic()
new_with_mnemonic (group:list=None, label:str) -> Gtk.Widget
Creates a new Gtk.RadioMenuItem
containing a label. The labelwill be created using `Gtk.Label:new_with_mnemonic
(), so underscoresin
label` indicate the mnemonic for the menu item.
- Returns: a new Gtk.RadioMenuItem
new_from_widget()
new_from_widget (group:Gtk.RadioMenuItem=None) -> Gtk.Widget
Creates a new Gtk.RadioMenuItem
adding it to the same group as group
.
[constructor]
Returns: The new
Gtk.RadioMenuItem
.Since: 2.4
new_with_label_from_widget()
new_with_label_from_widget (group:Gtk.RadioMenuItem=None, label:str=None) -> Gtk.Widget
Creates a new Gtk.RadioMenuItem
whose child is a simple Gtk.Label
.The new Gtk.RadioMenuItem
is added to the same group as group
.
[constructor]
Returns: The new
Gtk.RadioMenuItem
.Since: 2.4
new_with_mnemonic_from_widget()
new_with_mnemonic_from_widget (group:Gtk.RadioMenuItem=None, label:str=None) -> Gtk.Widget
Creates a new Gtk.RadioMenuItem
containing a label. The label will becreated using `Gtk.Label:new_with_mnemonic
(), so underscores in labelindicate the mnemonic for the menu item.
The new
Gtk.RadioMenuItemis added to the same group as
group`.
[constructor]
Returns: The new
Gtk.RadioMenuItem
.Since: 2.4
set_group()
set_group (self, group:list=None)
Sets the group of a radio menu item, or changes it.
get_group()
get_group (self) -> list
Returns the group to which the radio menu item belongs, as a GList ofGtk.RadioMenuItem
. The list belongs to GTK+ and should not be freed.
- Returns:
the groupof
radio_menu_item
.
join_group()
join_group (self, group_source:Gtk.RadioMenuItem=None)
Joins a Gtk.RadioMenuItem
object to the group of another Gtk.RadioMenuItem
object.
This function should be used by language bindings to avoid the memorymanangement of the opaque GSList of Gtk.RadioMenuItem:get_group()
and Gtk.RadioMenuItem:set_group()
.
A common way to set up a group of Gtk.RadioMenuItem
instances is:
Gtk.RadioMenuItem
last_item = None; while ( ...more items to add... ) { Gtk.RadioMenuItem
radio_item; radio_item = Gtk.RadioMenuItem:new (...); Gtk.RadioMenuItem:join_group (radio_item, last_item); last_item = radio_item; }
- Since: 3.18
Example:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="MenuItem Demo")
self.set_size_request(400, 300)
grid = Gtk.Grid()
self.add(grid)
menubar = Gtk.MenuBar()
menubar.set_hexpand(True)
grid.attach(menubar, 0, 0, 1, 1)
menuitem_file = Gtk.MenuItem(label="File")
menubar.append(menuitem_file)
submenu_file = Gtk.Menu()
menuitem_file.set_submenu(submenu_file)
menuitem_open = Gtk.MenuItem(label="Open")
submenu_file.append(menuitem_open)
menuitem_open.connect('activate', self.on_menu_open)
menuitem_quit = Gtk.MenuItem(label="Quit")
submenu_file.append(menuitem_quit)
menuitem_quit.connect('activate', self.on_menu_quit)
menuitem_edit = Gtk.MenuItem(label="Edit")
menubar.append(menuitem_edit)
menuitem = Gtk.MenuItem(label="RadioMenuItem")
menubar.append(menuitem)
menu = Gtk.Menu()
menuitem.set_submenu(menu)
radiomenuitem1 = Gtk.RadioMenuItem(label="RadioMenuItem 1")
radiomenuitem1.set_active(True)
menu.append(radiomenuitem1)
radiomenuitem2 = Gtk.RadioMenuItem(label="RadioMenuItem 2", group=radiomenuitem1)
menu.append(radiomenuitem2)
def on_menu_open(self, widget):
print("add file open dialog")
def on_menu_quit(self, widget):
Gtk.main_quit()
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()