Tk Source Code

View Ticket
Login
Ticket UUID: 2128087
Title: menubutton menu-traversal shortkeys doesn't work
Type: Bug Version: None
Submitter: nobody Created on: 2008-09-25 10:22:42
Subsystem: 13. Win Menus Assigned To: oehhar
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-07 08:25:35
Resolution: Fixed Closed By: oehhar
    Closed on: 2026-10-07 08:14:55
Description:
Please run by wish the following script under win32. The menu-traversal shortkey
doesn't work, but it works fine under linux :)

Thank you all.

[email protected]


#################################################################################
#!/usr/bin/wish

frame .f
pack .f -fill x

frame .f2
pack .f2


# the "-underline 0" switch should create a menu-traversal shortkey.
# Then using alt-f we aspect to open the menu.
# It works in linux, but not in win32 :(
#
menubutton .f.mb -text "File" -underline 0 -menu .f.mb.m

menu .f.mb.m -tearoff 0


.f.mb.m add command -label "dummy" -underline 0 -command {
}

.f.mb.m add command -label "exit" -underline 0 -command {
        exit
}

 
pack .f.mb -side left

label .f2.l -text "sample"
pack .f2.l -side bottom


focus -force .f
update
##########################################################
User Comments: serhiy.storchaka added on 2026-10-07 08:25:35:

Thank you for merging, Harald! The failure of unixEmbed-9.2 is not related to this fix: it fails sporadically on main too. It is [4a25f316f7], fixed in branch embed-container-destroyed, which is waiting for review.


oehhar added on 2026-10-07 08:04:37:

There is the following error in CI on unix https://github.com/tcltk/tk/actions/runs/37583015318/job/112666770424:

==== unixEmbed-9.2 EmbedWindowDeleted procedure, check embeddedPtr FAILED
==== Contents of test case:

    frame .f1 -container 1 -width 200 -height 50
    pack .f1
    update
    childTkProcess eval "set w1 [winfo id .f1]"
    childTkProcess eval {
	destroy {*}[winfo children .]
	toplevel .t1 -use $w1 -highlightthickness 2 -bd 2 -relief sunken
	set x {}
	lappend x [testembed]
	destroy .t1
	lappend x [testembed]
    }

---- Test generated error; Return code was: 1
---- Return code should have been one of: 0 2
---- errorInfo: error flushing "file8": broken pipe
    while executing
"flush $fd"
    (procedure "childTkProcess" line 44)
    invoked from within
"childTkProcess eval "set w1 [winfo id .f1]""
    ("uplevel" body line 5)
    invoked from within
"uplevel 1 $script"
---- errorCode: POSIX EPIPE {broken pipe}
==== unixEmbed-9.2 FAILED

This is IMHO not related to the patch.

Merged:

  • main: [ee3cc6ac]
  • core-9-0-branch [0818e1b8]

Thanks for all, Harald


oehhar added on 2026-10-07 07:18:10:

Closing by ESC failure is described in ticket [2225507]. This is also solved by the fix of this ticket.


oehhar added on 2026-10-06 18:17:28:

Thanks. The fix is effective.

There is a small visual difference between using the mouse and using Alt+F:

When pressing Alt+F, the Word "File" keeps its raised appearence while the menu is open. When pressing "File" with the mouse, the raised appearence is removed with click-down while the menu is open.

That is not an issue. IMHO it is even more logical (File stays raised while menu posted) then if it is not raised.

I will schedule the CI on the branch. If this is ok tomorrow, I will merge at least to main.

THanks for all, Harald


serhiy.storchaka added on 2026-10-05 18:06:45:

Thanks for testing. Fixed in [d6f980fca7]: posting a native menu does not return until it is closed, and after posting by keyboard no button release follows to restore the menubutton, so it stayed raised and ignored Alt+F. Tested on Windows. This should apply to macOS as well, but I could not test it there. Tests are added for the result of tk::TraverseToMenu, which is now 0 or 1 instead of an empty string.


oehhar added on 2026-10-05 17:09:39:

I have tested the patch in branch [win-alt-key-menubutton)] with the given script. It is effective and allows to open the File menu using the keys Alt+F.

I have observed the following point by the following steps:

  • start wish of the patched version
  • copy the upper test script to the console
  • Click into the wish window to give it focus
  • Press Alt+F to open the file menu
  • Observation: the parent menu (with "File") is now in a raised box. When using the mouse, it is only raised while clicking and returns quickly to the flat display.
  • Do one of the following actions to close the menu: a) press the d key; b) click right beside the text "File"
  • Issue: The File menu is still raised. It does not react any more on Alt+F.
  • Clicking the File menu with the mouse shows it back in flat display. Now, it is back sensitive.

I am not sure, if the patch is eventually incomplete.

I would love to have a CI run, as a test result was changed and other platforms should be tested.

Thanks for all, Harald


serhiy.storchaka added on 2026-09-19 09:42:05:

On Windows the Alt-Key traversal binding was only on the Menubutton class, so Alt+x posted a menubutton only when a menubutton had the focus, while the manual says it may be typed in any window of the toplevel. This is also how native applications behave: Alt+mnemonic activates a control from anywhere in the window. Fix in branch [e887343359]: the binding is on all windows as on X11; a native menubar is left to Windows.


[email protected] added on 2008-09-25 17:22:42:

File Added - 294835: err.tcl

Attachments: