Documentation‎ > ‎Menus‎ > ‎

gnocl::menu

A menu container widget.

Synopsis

gnocl::menu [-option value...]

Screenshot

Options

-children
type: list of widget-IDs (default: "")
List of menu items to be included in the menu.
-name
type: string
Name of the widget, can be used to set options in an rc file.
-sensitive
type: boolean (default: 1)
Whether or not the item is sensitive to user input.
-tearoff
type: boolean (default: 1)
Whether the menu can be torn off.
-title
type: string (default: "")
Title of the menu.
-visible
type: boolean (default: 1)
Whether or not the item is visible.

Description

A menu is a container widget which is either used in a menubar or as popup to get instantaneous user input.

Commands

id delete
Deletes the widget and the associated tcl command.
id configure [-option value...]
Configures the widget. Option may have any of the values accepted on creation of the widget.
id add list-of-widget-Ids
Add widgets to the menu.
id addBegin list-of-widget-Ids
Synonym for add.
id addEnd list-of-widget-Ids
Add widgets at the end of the menu.
id popup coordinates
Display widget as popup menu at specified x,y coordinates.

Examples

Simple menubar example

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"

package require Gnocl

set menu [gnocl::menu]

$menu add [gnocl::menuItem -text "%#New" -onClicked {puts "That's new"}]
$menu add [gnocl::menuSeparator]
$menu add [gnocl::menuItem -text "%#Quit" -onClicked exit ]

set file [gnocl::menuItem -text "%__File" -submenu $menu]

set menu [gnocl::menu]

$menu add [gnocl::menuItem -text "%__About" -onClicked {puts "Menu example"}]

set help [gnocl::menuItem -text "%__Help" -submenu $menu]
set box [gnocl::box -orientation vertical -borderWidth 0 -spacing 0]


$box add [gnocl::menuBar  -children [list $file $help]]

gnocl::window  -child $box -setSize 0.2

gnocl::mainLoop

Popup menus

set menu [gnocl::menu -title "menu"]

$menu add [gnocl::menuItem -text "%#Save" -onClicked {puts "save"}]
$menu add [gnocl::menuSeparator]
$menu add [gnocl::menuItem -text "%#Quit" -onClicked exit]

set but1 [gnocl::button -text "CLICKME" -onClicked {$menu popup %x %y} ]

gnocl::window -child $but1

Adding items to a text widget popup

    $txt configure -onPopulatePopup {
  
        set _menu [gnocl::menuItem \
            -icon %#Index \
            -text Preview \
            -data %d \
            -onClicked {
                gnocl::_notes_::viewNotes %d
                } ]
        set _sub_menu [gnocl::menu -tearoff 0]
        %w popup separator
        %w popup item $_menu
   
    }

Comments