g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.AccelLabel Gtk.AccelLabel Gtk.Buildable->Gtk.Widget Gtk.Label Gtk.Label Gtk.Label->Gtk.AccelLabel Gtk.Misc Gtk.Misc Gtk.Misc->Gtk.Label Gtk.Widget->Gtk.Misc




Inherited:Gtk.Label (50), Gtk.Misc (4), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10)
Structs:Gtk.WidgetClass (12), GObject.ObjectClass (5)
class new (string)
  get_accel ()
  get_accel_widget ()
  get_accel_width ()
  refetch ()
  set_accel (accelerator_key, accelerator_mods)
  set_accel_closure (accel_closure)
  set_accel_widget (accel_widget)


Inherited:Gtk.Label (20), Gtk.Misc (4), Gtk.Widget (39)
Name Type Flags Short Description
accel-closure GObject.Closure r/w/en The closure to be monitored for accelerator changes
accel-widget Gtk.Widget r/w/en The widget to be monitored for accelerator changes

Style Properties

Inherited:Gtk.Widget (17)


Inherited:Gtk.Label (5), Gtk.Widget (69), GObject.Object (1)
Name Type Access Description
label Gtk.Label r  

Class Details

class Gtk.AccelLabel(*args, **kwargs)

The Gtk.AccelLabel widget is a subclass of Gtk.Label that also displays an accelerator key on the right of the label text, e.g. “Ctrl+S”. It is commonly used in menus to show the keyboard short-cuts for commands.

The accelerator key to display is typically not set explicitly (although it can be, with Gtk.AccelLabel.set_accel()). Instead, the Gtk.AccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling Gtk.AccelLabel.set_accel_widget().

For example, a Gtk.MenuItem widget may have an accelerator added to emit the “activate” signal when the “Ctrl+S” key combination is pressed. A Gtk.AccelLabel is created and added to the Gtk.MenuItem, and Gtk.AccelLabel.set_accel_widget() is called with the Gtk.MenuItem as the second argument. The Gtk.AccelLabel will now display “Ctrl+S” after its label.

Note that creating a Gtk.MenuItem with Gtk.MenuItem.new_with_label() (or one of the similar functions for Gtk.CheckMenuItem and Gtk.RadioMenuItem) automatically adds a Gtk.AccelLabel to the Gtk.MenuItem and calls Gtk.AccelLabel.set_accel_widget() to set it up for you.

A Gtk.AccelLabel will only display accelerators which have Gtk.AccelFlags.VISIBLE set (see Gtk.AccelFlags). A Gtk.AccelLabel can display multiple accelerators and even signal names, though it is almost always used to display just one accelerator key.

Creating a simple menu item with an accelerator key.
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
GtkWidget *menu = gtk_menu_new ();
GtkWidget *save_item;
GtkAccelGroup *accel_group;

// Create a GtkAccelGroup and add it to the window.
accel_group = gtk_accel_group_new ();
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

// Create the menu item using the convenience function.
save_item = gtk_menu_item_new_with_label ("Save");
gtk_widget_show (save_item);
gtk_container_add (GTK_CONTAINER (menu), save_item);

// Now add the accelerator to the GtkMenuItem. Note that since we
// called gtk_menu_item_new_with_label() to create the GtkMenuItem
// the GtkAccelLabel is automatically set up to display the
// GtkMenuItem accelerators. We just need to make sure we use
gtk_widget_add_accelerator (save_item, "activate", accel_group,
                            GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
CSS nodes
╰── accelerator

Like Gtk.Label, Gtk.AccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.

classmethod new(string)[source]
Parameters:string (str) – the label string. Must be non-None.
Returns:a new Gtk.AccelLabel.
Return type:Gtk.Widget

Creates a new Gtk.AccelLabel.

 return location for the keyval
 return location for the modifier mask
Return type:(accelerator_key: int, accelerator_mods: Gdk.ModifierType)

Gets the keyval and modifier mask set with Gtk.AccelLabel.set_accel().

New in version 3.12.

Returns:the object monitored by the accelerator label, or None.
Return type:Gtk.Widget or None

Fetches the widget monitored by this accelerator label. See Gtk.AccelLabel.set_accel_widget().

Returns:the width needed to display the accelerator key(s).
Return type:int

Returns the width needed to display the accelerator key(s). This is used by menus to align all of the Gtk.MenuItem widgets, and shouldn’t be needed by applications.

Returns:always returns False.
Return type:bool

Recreates the string representing the accelerator keys. This should not be needed since the string is automatically updated whenever accelerators are added or removed from the associated widget.

set_accel(accelerator_key, accelerator_mods)[source]
  • accelerator_key (int) – a keyval, or 0
  • accelerator_mods (Gdk.ModifierType) – the modifier mask for the accel

Manually sets a keyval and modifier mask as the accelerator rendered by self.

If a keyval and modifier are explicitly set then these values are used regardless of any associated accel closure or widget.

Providing an accelerator_key of 0 removes the manual setting.

New in version 3.6.

Parameters:accel_closure (GObject.Closure or None) – the closure to monitor for accelerator changes, or None

Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see Gtk.AccelGroup.connect(). Passing None for accel_closure will dissociate self from its current closure, if any.

Parameters:accel_widget (Gtk.Widget or None) – the widget to be monitored, or None

Sets the widget to be monitored by this accelerator label. Passing None for accel_widget will dissociate self from its current widget, if any.

Property Details

Default Value:None

The closure to be monitored for accelerator changes

Default Value:None

The widget to be monitored for accelerator changes