Skip to content

Menu

Menu Screenshot

Menus display a list of options with single-key selection. Press a key to immediately execute the associated action.

Basic Usage

from ux3270.dialog import Menu

def handle_reports():
    print("Running reports...")

def handle_settings():
    print("Opening settings...")

menu = Menu("MAIN MENU", panel_id="MENU01")
menu.add_item("1", "Reports", handle_reports)
menu.add_item("2", "Settings", handle_settings)
menu.add_item("3", "Help", lambda: print("Help"))
menu.run()  # Loops until user exits

Single Show vs Run Loop

  • menu.show() - Display once, return selected key or None
  • menu.run() - Loop until user presses F3 or X to exit
# Single display
key = menu.show()
if key == "1":
    print("User selected option 1")

# Or loop
menu.run()  # Automatically loops

Exit Keys

  • F3 - Exit the menu
  • X - Also exits the menu

API Reference

ux3270.dialog.Menu

IBM 3270-style menu screen.

Displays a list of options with single-key selection. Follows IBM CUA (Common User Access) conventions: - Panel ID at top-left, title centered - Instruction line below title - Menu items in body area - Function keys at bottom

The dialog builds a Screen definition and hands control to Screen for all rendering and input handling.

__init__(title='MAIN MENU', panel_id='', instruction='Select an option')

Initialize a menu.

Parameters:

Name Type Description Default
title str

Menu title (displayed in uppercase per IBM convention)

'MAIN MENU'
panel_id str

Optional panel identifier (shown at top-left per CUA)

''
instruction str

Instruction text (shown on row 2 per CUA)

'Select an option'

add_item(key, label, action)

Add a menu item.

Parameters:

Name Type Description Default
key str

Single character key to select this item

required
label str

Display label

required
action Callable

Function to call when selected

required

Returns:

Type Description
Menu

Self for method chaining

show()

Display the menu and wait for user selection.

Returns:

Type Description
Optional[str]

Selected key, or None if user exits (F3 or X)

run()

Run the menu in a loop until user exits.