Object Hierarchy:

Gtk.Menu Gtk.Menu Gtk.Menu Gtk.MenuShell Gtk.MenuShell Gtk.MenuShell->Gtk.Menu Gtk.Container Gtk.Container Gtk.Container->Gtk.MenuShell Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Container GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.Menu Atk.Implementor->Gtk.MenuShell Atk.Implementor->Gtk.Container Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.Menu Gtk.Buildable->Gtk.MenuShell Gtk.Buildable->Gtk.Container Gtk.Buildable->Gtk.Widget


[ CCode ( type_id = "gtk_menu_get_type ()" ) ]
public class Menu : MenuShell, Implementor, Buildable

A Menu is a MenuShell that implements a drop down menu consisting of a list of MenuItem objects which can be navigated and activated by the user to perform application functions.

A Menu is most commonly dropped down by activating a MenuItem in a MenuBar or popped up by activating a MenuItem in another Menu.

A Menu can also be popped up by activating a ComboBox. Other composite widgets such as the Notebook can pop up a Menu as well.

Applications can display a Menu as a popup menu by calling the popup function. The example below shows how an application can pop up a menu when the 3rd mouse button is pressed.

Connecting the popup signal handler.

  // connect our handler which will popup the menu
g_signal_connect_swapped (window, "button_press_event",
G_CALLBACK (my_popup_handler), menu);

Signal handler which displays a popup menu.

static gint
my_popup_handler (GtkWidget *widget, GdkEvent *event)
GtkMenu *menu;
GdkEventButton *event_button;

g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);

// The "widget" is the menu that was supplied when
// g_signal_connect_swapped() was called.
menu = GTK_MENU (widget);

if (event->type == GDK_BUTTON_PRESS)
event_button = (GdkEventButton *) event;
if (event_button->button == GDK_BUTTON_SECONDARY)
gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
event_button->button, event_button->time);
return TRUE;

return FALSE;

CSS nodes

├── <child>

├── <child>
╰── arrow.bottom
Menu has name menu, and there are two subnodes with name arrow, for scrolling menu arrows. These subnodes get the .top and .bottom style classes.

Example: Menu:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.Menu";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);

// MenuBar:
Gtk.MenuBar bar = new Gtk.MenuBar ();
this.add (bar);

// File:
Gtk.MenuItem item_file = new Gtk.MenuItem.with_label ("File");
bar.add (item_file);

Gtk.Menu filemenu = new Gtk.Menu ();
item_file.set_submenu (filemenu);

Gtk.MenuItem item_open = new Gtk.MenuItem.with_label ("Open");
filemenu.add (item_open);

// Submenu:
Gtk.Menu submenu = new Gtk.Menu ();
item_open.set_submenu (submenu);

Gtk.MenuItem item_foo = new Gtk.MenuItem.with_label ("foo");
submenu.add (item_foo);

Gtk.MenuItem item_bar = new Gtk.MenuItem.with_label ("bar");
submenu.add (item_bar);

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;

valac --pkg gtk+-3.0 Gtk.Menu.vala

All known sub-classes:

Namespace: Gtk
Package: gtk+-3.0



Static methods:

Creation methods:



Inherited Members:

All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor