Gtk.MenuBar


Gtk.MenuBar — A subclass of Gtk.MenuShell which holds Gtk.MenuItem widgets

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.MenuShell
                    ╰── Gtk.MenuBar

See also:

Gtk.MenuShell, Gtk.Menu, Gtk.MenuItem


Functions:

Description:

The GtkMenuBar is a subclass of Gtk.MenuShell which contains one or more Gtk.MenuItems. The result is a standard menu bar which can hold many menu items.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.MenuBar

  • Returns: the new menu bar, as a Gtk.Widget

new_from_model()

new_from_model (model:Gio.MenuModel) -> Gtk.Widget

Creates a new Gtk.MenuBar and populates it with menu itemsand submenus according to model. The created menu items are connected to actions found in theGtk.ApplicationWindow to which the menu bar belongs - typicallyby means of being contained within the Gtk.ApplicationWindowswidget hierarchy.

  • Returns: a new Gtk.MenuBar

  • Since: 3.4


set_pack_direction()

set_pack_direction (self, pack_dir:Gtk.PackDirection)

Sets how items should be packed inside a menubar.

  • Since: 2.8

get_pack_direction()

get_pack_direction (self) -> Gtk.PackDirection

Retrieves the current pack direction of the menubar. See Gtk.MenuBar:set_pack_direction().

  • Returns: the pack direction

  • Since: 2.8


set_child_pack_direction()

set_child_pack_direction (self, child_pack_dir:Gtk.PackDirection)

Sets how widgets should be packed inside the children of a menubar.

  • Since: 2.8

get_child_pack_direction()

get_child_pack_direction (self) -> Gtk.PackDirection

Retrieves the current child pack direction of the menubar.See Gtk.MenuBar:set_child_pack_direction().

  • Returns: the child pack direction

  • Since: 2.8


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MyWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title="MenuBar Demo")
        self.set_size_request(400, 300)
        grid = Gtk.Grid()
        self.add(grid)

        menubar = Gtk.MenuBar()
        menubar.set_hexpand(True)
        grid.attach(menubar, 0, 0, 1, 1)

        menu_file = self.add_submenu(menubar, 'File')
        menu_open = self.add_menuitem(menu_file, 'Open')
        menu_open.connect('activate', self.on_menu_open)

        menu_quit = self.add_menuitem(menu_file, 'Quit')
        menu_quit.connect('activate', self.on_menu_quit)

        menu_edit = self.add_submenu(menubar, 'Edit')

    def add_submenu(self, menubar, label):
        menuitem = Gtk.MenuItem(label=label)
        menubar.append(menuitem)
        submenu = Gtk.Menu()
        menuitem.set_submenu(submenu)
        return menuitem

    def add_menuitem(self, submenu, label):
        menuitem = Gtk.MenuItem(label=label)
        submenu.append(menuitem)
        return menuitem

    def on_menu_open(self, widget):
        print("add file open dialog")

    def on_menu_quit(self, widget):
        Gtk.main_quit()


win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

results matching ""

    No results matching ""