Skip to main content
Ctrl+K

GNOME Python API

  • GLib
  • Gio
  • GObject
  • Gtk
  • Gdk
  • Adw
    • DBus
    • DBusGLib
    • Flatpak
    • GModule
    • Gcr
    • GdkPixbuf
    • GdkPixdata
    • GdkWayland
    • GdkX11
    • Graphene
    • Gsk
    • Gst
    • GstBase
    • GstCheck
    • GstController
    • GstNet
    • GtkSource
    • HarfBuzz
    • ICal
    • JavaScriptCore
    • Pango
    • PangoCairo
    • PangoFT2
    • PangoFc
    • PangoOT
    • PangoXft
    • Shumate
    • Soup
    • Vte
    • WebKit
    • WebKitWebProcessExtension
    • Xdp
    • XdpGtk4
    • pycairo
  • GLib
  • Gio
  • GObject
  • Gtk
  • Gdk
  • Adw
  • DBus
  • DBusGLib
  • Flatpak
  • GModule
  • Gcr
  • GdkPixbuf
  • GdkPixdata
  • GdkWayland
  • GdkX11
  • Graphene
  • Gsk
  • Gst
  • GstBase
  • GstCheck
  • GstController
  • GstNet
  • GtkSource
  • HarfBuzz
  • ICal
  • JavaScriptCore
  • Pango
  • PangoCairo
  • PangoFT2
  • PangoFc
  • PangoOT
  • PangoXft
  • Shumate
  • Soup
  • Vte
  • WebKit
  • WebKitWebProcessExtension
  • Xdp
  • XdpGtk4
  • pycairo

Section Navigation

API

  • Classes
    • ATContext
    • AboutDialog
    • ActionBar
    • ActivateAction
    • Adjustment
    • AlertDialog
    • AlternativeTrigger
    • AnyFilter
    • AppChooserButton
    • AppChooserDialog
    • AppChooserWidget
    • Application
    • ApplicationWindow
    • AspectFrame
    • Assistant
    • AssistantPage
    • BinLayout
    • BookmarkList
    • BoolFilter
    • Box
    • BoxLayout
    • Builder
    • Builder.BuilderScope
    • BuilderCScope
    • BuilderListItemFactory
    • Button
    • CClosureExpression
    • Calendar
    • CallbackAction
    • CellArea
    • CellAreaBox
    • CellAreaContext
    • CellRenderer
    • CellRendererAccel
    • CellRendererCombo
    • CellRendererPixbuf
    • CellRendererProgress
    • CellRendererSpin
    • CellRendererSpinner
    • CellRendererText
    • CellRendererToggle
    • CellView
    • CenterBox
    • CenterLayout
    • CheckButton
    • ClosureExpression
    • ColorButton
    • ColorChooserDialog
    • ColorChooserWidget
    • ColorDialog
    • ColorDialogButton
    • ColumnView
    • ColumnViewCell
    • ColumnViewColumn
    • ColumnViewRow
    • ColumnViewSorter
    • ComboBox
    • ComboBoxText
    • ConstantExpression
    • Constraint
    • ConstraintGuide
    • ConstraintLayout
    • ConstraintLayoutChild
    • CssProvider
    • CustomFilter
    • CustomLayout
    • CustomSorter
    • Dialog
    • DirectoryList
    • DragIcon
    • DragSource
    • DrawingArea
    • DropControllerMotion
    • DropDown
    • DropTarget
    • DropTargetAsync
    • EditableLabel
    • EmojiChooser
    • Entry
    • EntryBuffer
    • EntryCompletion
    • EventController
    • EventControllerFocus
    • EventControllerKey
    • EventControllerLegacy
    • EventControllerMotion
    • EventControllerScroll
    • EveryFilter
    • Expander
    • Expression
    • FileChooserDialog
    • FileChooserNative
    • FileChooserWidget
    • FileDialog
    • FileFilter
    • FileLauncher
    • Filter
    • FilterListModel
    • Fixed
    • FixedLayout
    • FixedLayoutChild
    • FlattenListModel
    • FlowBox
    • FlowBoxChild
    • FontButton
    • FontChooserDialog
    • FontChooserWidget
    • FontDialog
    • FontDialogButton
    • Frame
    • GLArea
    • Gesture
    • GestureClick
    • GestureDrag
    • GestureLongPress
    • GesturePan
    • GestureRotate
    • GestureSingle
    • GestureStylus
    • GestureSwipe
    • GestureZoom
    • GraphicsOffload
    • Grid
    • GridLayout
    • GridLayoutChild
    • GridView
    • HeaderBar
    • IMContext
    • IMContextSimple
    • IMMulticontext
    • IconPaintable
    • IconTheme
    • IconView
    • Image
    • InfoBar
    • Inscription
    • KeyvalTrigger
    • Label
    • LayoutChild
    • LayoutManager
    • LevelBar
    • LinkButton
    • ListBase
    • ListBox
    • ListBoxRow
    • ListHeader
    • ListItem
    • ListItemFactory
    • ListStore
    • ListView
    • LockButton
    • MapListModel
    • MediaControls
    • MediaFile
    • MediaStream
    • MenuButton
    • MessageDialog
    • MnemonicAction
    • MnemonicTrigger
    • MountOperation
    • MultiFilter
    • MultiSelection
    • MultiSorter
    • NamedAction
    • NativeDialog
    • NeverTrigger
    • NoSelection
    • Notebook
    • NotebookPage
    • NothingAction
    • NumericSorter
    • ObjectExpression
    • Overlay
    • OverlayLayout
    • OverlayLayoutChild
    • PadController
    • PageSetup
    • PageSetupUnixDialog
    • Paned
    • ParamSpecExpression
    • PasswordEntry
    • PasswordEntryBuffer
    • Picture
    • Popover
    • PopoverMenu
    • PopoverMenuBar
    • PrintContext
    • PrintDialog
    • PrintJob
    • PrintOperation
    • PrintSettings
    • PrintUnixDialog
    • Printer
    • ProgressBar
    • PropertyExpression
    • PyGTKDeprecationWarning
    • Range
    • RecentManager
    • Revealer
    • Scale
    • ScaleButton
    • Scrollbar
    • ScrolledWindow
    • SearchBar
    • SearchEntry
    • SelectionFilterModel
    • Separator
    • Settings
    • Shortcut
    • ShortcutAction
    • ShortcutController
    • ShortcutLabel
    • ShortcutTrigger
    • ShortcutsGroup
    • ShortcutsSection
    • ShortcutsShortcut
    • ShortcutsWindow
    • SignalAction
    • SignalListItemFactory
    • SingleSelection
    • SizeGroup
    • SliceListModel
    • Snapshot
    • SortListModel
    • Sorter
    • SpinButton
    • Spinner
    • Stack
    • StackPage
    • StackSidebar
    • StackSwitcher
    • Statusbar
    • StringFilter
    • StringList
    • StringObject
    • StringSorter
    • StyleContext
    • Switch
    • Template
    • Template.Callback
    • Template.Child
    • Text
    • TextBuffer
    • TextChildAnchor
    • TextMark
    • TextTag
    • TextTagTable
    • TextView
    • ToggleButton
    • Tooltip
    • TreeExpander
    • TreeListModel
    • TreeListRow
    • TreeListRowSorter
    • TreeModelFilter
    • TreeModelRow
    • TreeModelRowIter
    • TreeModelSort
    • TreeSelection
    • TreeStore
    • TreeView
    • TreeViewColumn
    • UriLauncher
    • Video
    • Viewport
    • VolumeButton
    • Widget
    • WidgetPaintable
    • Window
    • WindowControls
    • WindowGroup
    • WindowHandle
  • Interfaces
    • Accessible
    • AccessibleRange
    • AccessibleText
    • Actionable
    • AppChooser
    • Buildable
    • BuilderScope
    • CellEditable
    • CellLayout
    • ColorChooser
    • ConstraintTarget
    • Editable
    • FileChooser
    • FontChooser
    • Native
    • Orientable
    • PrintOperationPreview
    • Root
    • Scrollable
    • SectionModel
    • SelectionModel
    • ShortcutManager
    • StyleProvider
    • SymbolicPaintable
    • TreeDragDest
    • TreeDragSource
    • TreeModel
    • TreeSortable
  • Structures
    • AccessibleList
    • AccessibleTextRange
    • Bitset
    • BitsetIter
    • Border
    • BuildableParseContext
    • BuildableParser
    • CssLocation
    • CssSection
    • CssStyleChange
    • ExpressionWatch
    • PadActionEntry
    • PageRange
    • PaperSize
    • PrintBackend
    • PrintSetup
    • RecentData
    • RecentInfo
    • RequestedSize
    • Requisition
    • ScrollInfo
    • TextIter
    • TreeIter
    • TreePath
    • TreeRowData
    • TreeRowReference
  • Enums
    • AccessibleAnnouncementPriority
    • AccessibleAutocomplete
    • AccessibleInvalidState
    • AccessiblePlatformState
    • AccessibleProperty
    • AccessibleRelation
    • AccessibleRole
    • AccessibleSort
    • AccessibleState
    • AccessibleTextContentChange
    • AccessibleTextGranularity
    • AccessibleTristate
    • Align
    • ApplicationInhibitFlags
    • ArrowType
    • AssistantPageType
    • BaselinePosition
    • BorderStyle
    • BuilderClosureFlags
    • BuilderError
    • ButtonsType
    • CellRendererAccelMode
    • CellRendererMode
    • CellRendererState
    • Collation
    • ConstraintAttribute
    • ConstraintRelation
    • ConstraintStrength
    • ConstraintVflParserError
    • ContentFit
    • CornerType
    • CssParserError
    • CssParserWarning
    • DebugFlags
    • DeleteType
    • DialogError
    • DialogFlags
    • DirectionType
    • EditableProperties
    • EntryIconPosition
    • EventControllerScrollFlags
    • EventSequenceState
    • FileChooserAction
    • FileChooserError
    • FilterChange
    • FilterMatch
    • FontChooserLevel
    • FontLevel
    • FontRendering
    • GraphicsOffloadEnabled
    • IconLookupFlags
    • IconSize
    • IconThemeError
    • IconViewDropPosition
    • ImageType
    • InputHints
    • InputPurpose
    • InscriptionOverflow
    • Justification
    • LevelBarMode
    • License
    • ListScrollFlags
    • ListTabBehavior
    • MessageType
    • MovementStep
    • NaturalWrapMode
    • NotebookTab
    • NumberUpLayout
    • Ordering
    • Orientation
    • Overflow
    • PackType
    • PadActionType
    • PageOrientation
    • PageSet
    • PanDirection
    • PickFlags
    • PolicyType
    • PopoverMenuFlags
    • PositionType
    • PrintCapabilities
    • PrintDuplex
    • PrintError
    • PrintOperationAction
    • PrintOperationResult
    • PrintPages
    • PrintQuality
    • PrintStatus
    • PropagationLimit
    • PropagationPhase
    • RecentManagerError
    • ResponseType
    • RevealerTransitionType
    • ScrollStep
    • ScrollType
    • ScrollablePolicy
    • SelectionMode
    • SensitivityType
    • ShortcutActionFlags
    • ShortcutScope
    • ShortcutType
    • SizeGroupMode
    • SizeRequestMode
    • SortType
    • SorterChange
    • SorterOrder
    • SpinButtonUpdatePolicy
    • SpinType
    • StackTransitionType
    • StateFlags
    • StringFilterMatchMode
    • StyleContextPrintFlags
    • SymbolicColor
    • SystemSetting
    • TextBufferNotifyFlags
    • TextDirection
    • TextExtendSelection
    • TextSearchFlags
    • TextViewLayer
    • TextWindowType
    • TreeModelFlags
    • TreeViewColumnSizing
    • TreeViewDropPosition
    • TreeViewGridLines
    • Unit
    • WrapMode
  • Functions
  • Constants
  • Gtk
  • Classes
  • MenuButton

MenuButton#

class MenuButton(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

The GtkMenuButton widget is used to display a popup when clicked.

https://docs.gtk.org/gtk4/menu-button.png

This popup can be provided either as a GtkPopover or as an abstract GMenuModel.

The GtkMenuButton widget can show either an icon (set with the icon_name property) or a label (set with the label property). If neither is explicitly set, a Image is automatically created, using an arrow image oriented according to direction or the generic “open-menu-symbolic” icon if the direction is not set.

The positioning of the popup is determined by the direction property of the menu button.

For menus, the halign and valign properties of the menu are also taken into account. For example, when the direction is DOWN and the horizontal alignment is 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”.

start

center

end

down

https://docs.gtk.org/gtk4/down-start.png https://docs.gtk.org/gtk4/down-center.png https://docs.gtk.org/gtk4/down-end.png

up

https://docs.gtk.org/gtk4/up-start.png https://docs.gtk.org/gtk4/up-center.png https://docs.gtk.org/gtk4/up-end.png

left

https://docs.gtk.org/gtk4/left-start.png https://docs.gtk.org/gtk4/left-center.png https://docs.gtk.org/gtk4/left-end.png

right

https://docs.gtk.org/gtk4/right-start.png https://docs.gtk.org/gtk4/right-center.png https://docs.gtk.org/gtk4/right-end.png

CSS nodes#

menubutton
╰── button.toggle
    ╰── <content>
         ╰── [arrow]

GtkMenuButton has a single CSS node with name menubutton which contains a button node with a .toggle style class.

If the button contains an icon, it will have the .image-button style class, if it contains text, it will have .text-button style class. If an arrow is visible in addition to an icon, text or a custom child, it will also have .arrow-button style class.

Inside the toggle button content, there is an arrow node for the indicator, which will carry one of the .none, .up, .down, .left or .right style classes to indicate the direction that the menu will appear in. The CSS is expected to provide a suitable image for each of these cases using the -gtk-icon-source property.

Optionally, the menubutton node can carry the .circular style class to request a round appearance.

Accessibility#

GtkMenuButton uses the BUTTON role.

Constructors#

class MenuButton
classmethod new() → Widget#

Creates a new GtkMenuButton widget with downwards-pointing arrow as the only child.

You can replace the child widget with another GtkWidget should you wish to.

Methods#

class MenuButton
get_active() → bool#

Returns whether the menu button is active.

Added in version 4.10.

get_always_show_arrow() → bool#

Gets whether to show a dropdown arrow even when using an icon or a custom child.

Added in version 4.4.

get_can_shrink() → bool#

Retrieves whether the button can be smaller than the natural size of its contents.

Added in version 4.12.

get_child() → Widget | None#

Gets the child widget of menu_button.

Added in version 4.6.

get_direction() → ArrowType#

Returns the direction the popup will be pointing at when popped up.

get_has_frame() → bool#

Returns whether the button has a frame.

get_icon_name() → str | None#

Gets the name of the icon shown in the button.

get_label() → str | None#

Gets the label shown in the button

get_menu_model() → MenuModel | None#

Returns the GMenuModel used to generate the popup.

get_popover() → Popover | None#

Returns the GtkPopover that pops out of the button.

If the button is not using a GtkPopover, this function returns None.

get_primary() → bool#

Returns whether the menu button acts as a primary menu.

Added in version 4.4.

get_use_underline() → bool#

Returns whether an embedded underline in the text indicates a mnemonic.

popdown() → None#

Dismiss the menu.

popup() → None#

Pop up the menu.

set_active(active: bool) → None#

Sets whether the menu button is active.

Added in version 4.10.

Parameters:

active – whether the menu button is active

set_always_show_arrow(always_show_arrow: bool) → None#

Sets whether to show a dropdown arrow even when using an icon or a custom child.

Added in version 4.4.

Parameters:

always_show_arrow – whether to show a dropdown arrow even when using an icon or a custom child

set_can_shrink(can_shrink: bool) → None#

Sets whether the button size can be smaller than the natural size of its contents.

For text buttons, setting can_shrink to true will ellipsize the label.

For icon buttons, this function has no effect.

Added in version 4.12.

Parameters:

can_shrink – whether the button can shrink

set_child(child: Widget | None = None) → None#

Sets the child widget of menu_button.

Setting a child resets label and icon_name.

If always_show_arrow is set to TRUE and direction is not GTK_ARROW_NONE, a dropdown arrow will be shown next to the child.

Added in version 4.6.

Parameters:

child – the child widget

set_create_popup_func(func: Callable[[MenuButton, Any], None] | None = None, user_data: Any = None) → None#

Sets func to be called when a popup is about to be shown.

func should use one of

  • set_popover

  • set_menu_model

to set a popup for menu_button. If func is non-None, menu_button will always be sensitive.

Using this function will not reset the menu widget attached to menu_button. Instead, this can be done manually in func.

Parameters:
  • func – function to call when a popup is about to be shown, but none has been provided via other means, or None to reset to default behavior

  • user_data – user data to pass to func

set_direction(direction: ArrowType) → None#

Sets the direction in which the popup will be popped up.

If the button is automatically populated with an arrow icon, its direction will be changed to match.

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 NONE for a direction, the popup will behave as if you passed DOWN (although you won’t see any arrows).

Parameters:

direction – a GtkArrowType

set_has_frame(has_frame: bool) → None#

Sets the style of the button.

Parameters:

has_frame – whether the button should have a visible frame

set_icon_name(icon_name: str) → None#

Sets the name of an icon to show inside the menu button.

Setting icon name resets label and child.

If always_show_arrow is set to TRUE and direction is not GTK_ARROW_NONE, a dropdown arrow will be shown next to the icon.

Parameters:

icon_name – the icon name

set_label(label: str) → None#

Sets the label to show inside the menu button.

Setting a label resets icon_name and child.

If direction is not GTK_ARROW_NONE, a dropdown arrow will be shown next to the label.

Parameters:

label – the label

set_menu_model(menu_model: MenuModel | None = None) → None#

Sets the GMenuModel from which the popup will be constructed.

If menu_model is None, the button is disabled.

A Popover will be created from the menu model with new_from_model. Actions will be connected as documented for this function.

If popover is already set, it will be dissociated from the menu_button, and the property is set to None.

Parameters:

menu_model – a GMenuModel, or None to unset and disable the button

set_popover(popover: Widget | None = None) → None#

Sets the GtkPopover that will be popped up when the menu_button is clicked.

If popover is None, the button is disabled.

If menu_model is set, the menu model is dissociated from the menu_button, and the property is set to None.

Parameters:

popover – a GtkPopover, or None to unset and disable the button

set_primary(primary: bool) → None#

Sets whether menu button acts as a primary menu.

Primary menus can be opened with the F10 key.

Added in version 4.4.

Parameters:

primary – whether the menubutton should act as a primary menu

set_use_underline(use_underline: bool) → None#

If true, an underline in the text indicates a mnemonic.

Parameters:

use_underline – True if underlines in the text indicate mnemonics

Properties#

class MenuButton
props.active: bool#

The type of the None singleton.

Added in version 4.10.

props.always_show_arrow: bool#

The type of the None singleton.

Added in version 4.4.

props.can_shrink: bool#

The type of the None singleton.

Added in version 4.12.

props.child: Widget#

The type of the None singleton.

Added in version 4.6.

props.direction: ArrowType#

The type of the None singleton.

props.has_frame: bool#

The type of the None singleton.

props.icon_name: str#

The type of the None singleton.

props.label: str#

The type of the None singleton.

props.menu_model: MenuModel#

The type of the None singleton.

props.popover: Popover#

The type of the None singleton.

props.primary: bool#

The type of the None singleton.

Added in version 4.4.

props.use_underline: bool#

The type of the None singleton.

Signals#

class MenuButton.signals
activate() → None#

Emitted to when the menu button is activated.

The ::activate signal on GtkMenuButton is an action signal and emitting it causes the button to pop up its menu.

Added in version 4.4.

On this page
  • CSS nodes
  • Accessibility
  • Constructors
    • MenuButton.new()
  • Methods
    • MenuButton.get_active()
    • MenuButton.get_always_show_arrow()
    • MenuButton.get_can_shrink()
    • MenuButton.get_child()
    • MenuButton.get_direction()
    • MenuButton.get_has_frame()
    • MenuButton.get_icon_name()
    • MenuButton.get_label()
    • MenuButton.get_menu_model()
    • MenuButton.get_popover()
    • MenuButton.get_primary()
    • MenuButton.get_use_underline()
    • MenuButton.popdown()
    • MenuButton.popup()
    • MenuButton.set_active()
    • MenuButton.set_always_show_arrow()
    • MenuButton.set_can_shrink()
    • MenuButton.set_child()
    • MenuButton.set_create_popup_func()
    • MenuButton.set_direction()
    • MenuButton.set_has_frame()
    • MenuButton.set_icon_name()
    • MenuButton.set_label()
    • MenuButton.set_menu_model()
    • MenuButton.set_popover()
    • MenuButton.set_primary()
    • MenuButton.set_use_underline()
  • Properties
    • MenuButton.props.active
    • MenuButton.props.always_show_arrow
    • MenuButton.props.can_shrink
    • MenuButton.props.child
    • MenuButton.props.direction
    • MenuButton.props.has_frame
    • MenuButton.props.icon_name
    • MenuButton.props.label
    • MenuButton.props.menu_model
    • MenuButton.props.popover
    • MenuButton.props.primary
    • MenuButton.props.use_underline
  • Signals
    • MenuButton.signals.activate()

This Page

  • Show Source

Created using Sphinx 8.2.3.

General Index

Built with the PyData Sphinx Theme 0.16.1.