Skip to content

Gtk.PopoverMenuBar

class — extends Widget, Accessible, Buildable, ConstraintTarget

Presents a horizontal bar of items that pop up menus when clicked.

<picture> <source srcset="menubar-dark.png" media="(prefers-color-scheme: dark)"> <img alt="An example GtkPopoverMenuBar" src="menubar.png"> </picture>

The only way to create instances of GtkPopoverMenuBar is from a GMenuModel.

CSS nodes

menubar
├── item[.active]
┊   ╰── popover
╰── item
    ╰── popover

GtkPopoverMenuBar has a single CSS node with name menubar, below which each item has its CSS node, and below that the corresponding popover.

The item whose popover is currently open gets the .active style class.

Accessibility

GtkPopoverMenuBar uses the AccessibleRole.menu_bar role, the menu items use the AccessibleRole.menu_item role and the menus use the AccessibleRole.menu role.

Constructors

new_from_model

@classmethod
def new_from_model(cls, model: Gio.MenuModel | None = ...) -> Widget

Creates a GtkPopoverMenuBar from a GMenuModel.

Parameters:

  • model — a GMenuModel

Methods

add_child

def add_child(self, child: Widget, id: str) -> bool

Adds a custom widget to a generated menubar.

For this to work, the menu model of bar must have an item with a custom attribute that matches id.

Parameters:

  • child — the GtkWidget to add
  • id — the ID to insert child at

get_menu_model

def get_menu_model(self) -> Gio.MenuModel | None

Returns the model from which the contents of bar are taken.

remove_child

def remove_child(self, child: Widget) -> bool

Removes a widget that has previously been added with PopoverMenuBar.add_child.

Parameters:

  • child — the GtkWidget to remove

set_menu_model

def set_menu_model(self, model: Gio.MenuModel | None = ...) -> None

Sets a menu model from which bar should take its contents.

Parameters:

  • model — a GMenuModel

Properties

menu_model

menu_model: Gio.MenuModel  # read/write

The GMenuModel from which the menu bar is created.

The model should only contain submenus as toplevel elements.