GNOME Python API

References

  • PyGObject Docs
  • GNOME Developer Documentation

Libraries

  • Adw
  • DBus
  • DBusGLib
  • Flatpak
  • GLib
  • GModule
  • GObject
  • Gcr
  • Gdk
  • GdkPixbuf
  • GdkPixdata
  • GdkWayland
  • GdkX11
  • Gio
  • Graphene
  • Gsk
  • Gst
  • GstBase
  • GstCheck
  • GstController
  • GstNet
  • Gtk
    • 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
    • Structures
    • Enums
    • Functions
    • Constants
    • Dependencies
  • GtkSource
  • HarfBuzz
  • Pango
  • PangoCairo
  • PangoFT2
  • PangoFc
  • PangoOT
  • PangoXft
  • Shumate
  • Soup
  • Vte
  • WebKit
  • WebKitWebProcessExtension
  • Xdp
  • XdpGtk4
  • pycairo
GNOME Python API
  • Gtk
  • Classes
  • MenuButton
  • View page source

MenuButton

class MenuButton(**properties: Any)

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

Constructors:

MenuButton(**properties)
new() -> Gtk.Widget

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[[...], None] | None = None, *user_data: Any) → 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

Whether the menu button is active.

Added in version 4.10.

props.always_show_arrow: bool

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

Added in version 4.4.

props.can_shrink: bool

Whether the size of the button can be made smaller than the natural size of its contents.

Added in version 4.12.

props.child: Widget

The child widget.

Added in version 4.6.

props.direction: ArrowType

The GtkArrowType representing the direction in which the menu or popover will be popped out.

props.has_frame: bool

Whether the button has a frame.

props.icon_name: str

The name of the icon used to automatically populate the button.

props.label: str

The label for the button.

props.menu_model: MenuModel

The GMenuModel from which the popup will be created.

See set_menu_model for the interaction with the popover property.

props.popover: Popover

The GtkPopover that will be popped up when the button is clicked.

props.primary: bool

Whether the menu button acts as a primary menu.

Primary menus can be opened using the F10 key

Added in version 4.4.

props.use_underline: bool

If set an underscore in the text indicates a mnemonic.

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.


Built with Sphinx using a theme provided by Read the Docs.
  • MenuButton
    • 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()