Menus on Windows
On Windows each menu of a script is a menu of Windows. This page shows the menu bar of a window, the keys of the menus, and the context menus.
The menu bar
Give a toplevel a menu bar with -menu, as in Tk. The bar is the menu bar of Windows, under the title bar of the window:
menu .bar
. configure -menu .bar
menu .bar.file -tearoff 0
.bar add cascade -label File -menu .bar.file -underline 0
.bar.file add command -label "New" -accelerator Ctrl+N -command newDoc
.bar.file add command -label "Open..." -accelerator Ctrl+O -command openDoc
.bar.file add separator
.bar.file add command -label "Exit" -accelerator Alt+F4 -command exit
proc newDoc {} {puts new}
proc openDoc {} {puts open}
A cascade with the name help, such as .bar.help, goes at the right end of the bar.
Open a menu with the keys
Alt and F10 open the menu bar. Alt with the letter of -underline opens the menu with that letter, so Alt+F opens File in the script above.
Windows underlines that letter. In an open menu, the arrow keys move, Enter chooses, and Esc closes the menu.
Keys of the menu items
-accelerator is the text that the menu shows at the right of the label. As in Tk, a binding of the script runs the command for the key:
bind all <Control-n> newDoc
bind all <Control-o> openDoc
Write the accelerator as Windows apps write it: Ctrl+N, Ctrl+Shift+S, Alt+F4, F5. On macOS a script writes Command-N and binds <Command-n>. Keys of the menu items has one script for both.
Check and radio items, cascades, and state
| Entry | On Windows |
|---|---|
checkbutton |
A check mark while its variable is on. |
radiobutton |
A mark on the entry of the current value. |
cascade |
A submenu. |
separator |
The line of Windows. |
-state disabled |
A gray item that runs no command. |
menu .bar
. configure -menu .bar
menu .bar.view -tearoff 0
.bar add cascade -label View -menu .bar.view -underline 0
.bar.view add checkbutton -label "Show Sidebar" -variable sidebar
.bar.view add separator
.bar.view add radiobutton -label "Small" -variable size -value small
.bar.view add radiobutton -label "Large" -variable size -value large
set sidebar 1
set size small
-postcommand runs before the menu opens, and a change of the active item sends <<MenuSelect>>. A menu of Windows shows the label, the underline, the accelerator, the mark, and the state of each entry. It does not show the -image, the -font, or the colors of an entry, and it has no tear-off entry.
Context menus
tk_popup opens a menu of Windows at the pointer. Bind it to button 3, the right button:
menu .ctx -tearoff 0
.ctx add command -label Cut -command {puts cut}
.ctx add command -label Copy -command {puts copy}
.ctx add command -label Paste -command {puts paste}
text .t -width 40 -height 6
pack .t -padx 10 -pady 10
bind .t <Button-3> {tk_popup .ctx %X %Y}

tk_popup opens a menu of Windows.The menu of a menubutton, a ttk::menubutton, and tk_optionMenu is also a menu of Windows.

ztk examples/platform-gallery.tcl menu=1.The menu bar and the popup menus follow the light or dark scheme of the app. The dark menus need Windows 10 version 1903 or later.
The next page, Windows features, shows the parts of Windows that a script reaches.