Enaml
  • Getting Started
  • Developer Guides
  • Architecture Reference
  • FAQs
  • Examples
    • Tutorial Examples
    • Widgets Examples
      • Buttons Example
      • Context Menu Example
      • Dates Example
      • Dock Area Example
      • Dock Pane Example
      • Drag And Drop Example
      • Dual Slider Example
      • Field Example
      • File Dialog Example
      • Flow Area Example
      • Focus Traversal Example
      • Form Spacing Example
      • Form Example
      • Group Box Example
      • H Group Example
      • Image View Example
      • Ipython Console Example
      • Main Window Example
      • Menu Bar Example
      • Mdi Area Example
      • Mpl Canvas Example
      • Notebook Example
      • Popup Menu Example
      • Popup View Example
      • Progress Bar Example
      • Scroll Area Example
      • Slider Example
      • Spin Box Example
      • Splitter Example
      • Tool Bar Example
      • Tool Buttons Example
      • V Group Example
      • Vtk Canvas Example
      • Window Example
      • Window Children Example
    • Layout Examples
    • Stdlib Examples
    • Dynamic Examples
    • Aliases Examples
    • Functions Examples
    • Styling Examples
    • Templates Examples
    • Applib Examples
    • Workbench Examples
  • API Reference
  • Command Reference
  • Developer Notes
Enaml
  • Examples
  • Popup Menu Example

Popup Menu Example

This example demonstrates how to popup a menu.

A menu can be popped up in 2-ways. The first is by declaring the menu as a child of a widget and setting the ‘context_menu’ attribute to True. The second method is by creating the menu on-demand, and then invoking it’s ‘popup()’ method to show the menu at the current mouse location.

Tip

To see this example in action, download it from popup_menu and run:

$ enaml-run popup_menu.enaml

Screenshot

../_images/ex_popup_menu.png

Example Enaml Code

#------------------------------------------------------------------------------
# Copyright (c) 2013-2024, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" This example demonstrates how to popup a menu.

A menu can be popped up in 2-ways. The first is by declaring the menu as
a child of a widget and setting the 'context_menu' attribute to True. The
second method is by creating the menu on-demand, and then invoking it's
'popup()' method to show the menu at the current mouse location.

<< autodoc-me >>
"""
from __future__ import print_function
from enaml.widgets.api import (
    Window, Container, PushButton, Menu, Action, Field
)


enamldef PopupMenu(Menu):
    Action:
        text = 'foo'
        triggered :: print(text + ' triggered')
    Action:
        text = 'bar'
        triggered :: print(text + ' triggered')
    Action:
        text = 'baz'
        triggered :: print(text + ' triggered')
    Action:
        text = 'spam'
        triggered :: print(text + ' triggered')
    Action:
        text = 'ham'
        triggered :: print(text + ' triggered')


enamldef Main(Window):
    Container:
        PushButton:
            text = 'Popup Menu'
            clicked :: PopupMenu().popup()
        Field:
            text = 'Context Menu'
            read_only = True
            PopupMenu:
                context_menu = True
Previous Next

© Copyright 2013-2024, Nucleic Development Team. Last updated on Mar 24, 2025.

Built with Sphinx using a theme provided by Read the Docs.