Gtk.MenuButton¶
Example¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.ToggleButton (10), Gtk.Button (29), Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Actionable (5), Gtk.Activatable (6)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
Properties¶
- Inherited:
Gtk.ToggleButton (3), Gtk.Button (9), Gtk.Container (3), Gtk.Widget (39), Gtk.Actionable (2), Gtk.Activatable (2)
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
The parent widget which the menu should align with. |
||
r/w/en |
The direction the arrow should point. |
||
r/w |
The model from which the popup is made. |
||
r/w |
The popover |
||
r/w |
The dropdown menu. |
||
r/w/en |
Use a popover instead of a menu |
Style Properties¶
- Inherited:
Signals¶
Fields¶
- Inherited:
Gtk.ToggleButton (1), Gtk.Button (6), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)
Name |
Type |
Access |
Description |
---|---|---|---|
parent |
r |
Class Details¶
- class Gtk.MenuButton(*args, **kwargs)¶
- Bases:
- Abstract:
No
- Structure:
The
Gtk.MenuButton
widget is used to display a popup when clicked on. This popup can be provided either as aGtk.Menu
, aGtk.Popover
or an abstractGio.MenuModel
.The
Gtk.MenuButton
widget can hold any valid child widget. That is, it can hold almost any other standardGtk.Widget
. The most commonly used child isGtk.Image
. If no widget is explicitely added to theGtk.MenuButton
, aGtk.Image
is automatically created, using an arrow image oriented according toGtk.MenuButton
:direction
or the generic “open-menu-symbolic” icon if the direction is not set.The positioning of the popup is determined by the
Gtk.MenuButton
:direction
property of the menu button.For menus, the
Gtk.Widget
:halign
andGtk.Widget
:valign
properties of the menu are also taken into account. For example, when the direction isGtk.ArrowType.DOWN
and the horizontal alignment isGtk.Align.START
, the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is “pushed in”.- Direction = Down
halign = start
halign = center
halign = end
- Direction = Up
halign = start
halign = center
halign = end
- Direction = Left
valign = start
valign = center
valign = end
- Direction = Right
valign = start
valign = center
valign = end
- CSS nodes
Gtk.MenuButton
has a single CSS node with name button. To differentiate it from a plainGtk.Button
, it gets the .popup style class.- classmethod new()[source]¶
- Returns:
The newly created
Gtk.MenuButton
widget- Return type:
Creates a new
Gtk.MenuButton
widget with downwards-pointing arrow as the only child. You can replace the child widget with anotherGtk.Widget
should you wish to.New in version 3.6.
- get_align_widget()[source]¶
- Returns:
a
Gtk.Widget
value orNone
- Return type:
Gtk.Widget
orNone
Returns the parent
Gtk.Widget
to use to line up with menu.New in version 3.6.
- get_direction()[source]¶
- Returns:
a
Gtk.ArrowType
value- Return type:
Returns the direction the popup will be pointing at when popped up.
New in version 3.6.
- get_menu_model()[source]¶
- Returns:
a
Gio.MenuModel
orNone
- Return type:
Returns the
Gio.MenuModel
used to generate the popup.New in version 3.6.
- get_popover()[source]¶
- Returns:
a
Gtk.Popover
orNone
- Return type:
Gtk.Popover
orNone
Returns the
Gtk.Popover
that pops out of the button. If the button is not using aGtk.Popover
, this function returnsNone
.New in version 3.12.
- get_popup()[source]¶
-
Returns the
Gtk.Menu
that pops out of the button. If the button does not use aGtk.Menu
, this function returnsNone
.New in version 3.6.
- get_use_popover()[source]¶
- Returns:
True
if using aGtk.Popover
- Return type:
Returns whether a
Gtk.Popover
or aGtk.Menu
will be constructed from the menu model.New in version 3.12.
- set_align_widget(align_widget)[source]¶
- Parameters:
align_widget (
Gtk.Widget
orNone
) – aGtk.Widget
Sets the
Gtk.Widget
to use to line the menu with when popped up. Note that the align_widget must contain theGtk.MenuButton
itself.Setting it to
None
means that the menu will be aligned with the button itself.Note that this property is only used with menus currently, and not for popovers.
New in version 3.6.
- set_direction(direction)[source]¶
- Parameters:
direction (
Gtk.ArrowType
) – aGtk.ArrowType
Sets the direction in which the popup will be popped up, as well as changing the arrow’s direction. The child will not be changed to an arrow if it was customized.
If the does not fit in the available space in the given direction, GTK+ will its best to keep it inside the screen and fully visible.
If you pass
Gtk.ArrowType.NONE
for a direction, the popup will behave as if you passedGtk.ArrowType.DOWN
(although you won’t see any arrows).New in version 3.6.
- set_menu_model(menu_model)[source]¶
- Parameters:
menu_model (
Gio.MenuModel
orNone
) – aGio.MenuModel
, orNone
to unset and disable the button
Sets the
Gio.MenuModel
from which the popup will be constructed, orNone
to dissociate any existing menu model and disable the button.Depending on the value of
Gtk.MenuButton
:use-popover
, either aGtk.Menu
will be created withGtk.Menu.new_from_model
(), or aGtk.Popover
withGtk.Popover.new_from_model
(). In either case, actions will be connected as documented for these functions.If
Gtk.MenuButton
:popup
orGtk.MenuButton
:popover
are already set, those widgets are dissociated from the self, and those properties are set toNone
.New in version 3.6.
- set_popover(popover)[source]¶
- Parameters:
popover (
Gtk.Widget
orNone
) – aGtk.Popover
, orNone
to unset and disable the button
Sets the
Gtk.Popover
that will be popped up when the self is clicked, orNone
to dissociate any existing popover and disable the button.If
Gtk.MenuButton
:menu-model
orGtk.MenuButton
:popup
are set, those objects are dissociated from the self, and those properties are set toNone
.New in version 3.12.
- set_popup(menu)[source]¶
- Parameters:
menu (
Gtk.Widget
orNone
) – aGtk.Menu
, orNone
to unset and disable the button
Sets the
Gtk.Menu
that will be popped up when the self is clicked, orNone
to dissociate any existing menu and disable the button.If
Gtk.MenuButton
:menu-model
orGtk.MenuButton
:popover
are set, those objects are dissociated from the self, and those properties are set toNone
.New in version 3.6.
- set_use_popover(use_popover)[source]¶
-
Sets whether to construct a
Gtk.Popover
instead ofGtk.Menu
whenGtk.MenuButton.set_menu_model
() is called. Note that this property is only consulted when a new menu model is set.New in version 3.12.
Property Details¶
- Gtk.MenuButton.props.align_widget¶
- Name:
align-widget
- Type:
- Default Value:
- Flags:
The
Gtk.Widget
to use to align the menu with.New in version 3.6.
- Gtk.MenuButton.props.direction¶
- Name:
direction
- Type:
- Default Value:
- Flags:
The
Gtk.ArrowType
representing the direction in which the menu or popover will be popped out.New in version 3.6.
- Gtk.MenuButton.props.menu_model¶
- Name:
menu-model
- Type:
- Default Value:
- Flags:
The
Gio.MenuModel
from which the popup will be created. Depending on theGtk.MenuButton
:use-popover
property, that may be a menu or a popover.See
Gtk.MenuButton.set_menu_model
() for the interaction with theGtk.MenuButton
:popup
property.New in version 3.6.
- Gtk.MenuButton.props.popover¶
- Name:
popover
- Type:
- Default Value:
- Flags:
The
Gtk.Popover
that will be popped up when the button is clicked.New in version 3.12.
- Gtk.MenuButton.props.popup¶
-
The
Gtk.Menu
that will be popped up when the button is clicked.New in version 3.6.
- Gtk.MenuButton.props.use_popover¶
- Name:
use-popover
- Type:
- Default Value:
- Flags:
Whether to construct a
Gtk.Popover
from the menu model, or aGtk.Menu
.New in version 3.12.