Tk Source Code

View Ticket
Login
Ticket UUID: 585003
Title: tk_popup platform differences
Type: Bug Version: obsolete: 8.3.4
Submitter: rohanpall Created on: 2002-07-22 16:45:02
Subsystem: 81. Portability Assigned To: aku
Priority: 4 Severity: Minor
Status: Closed Last Modified: 2026-10-21 19:04:31
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-10-21 19:04:31
Description:
tk_popup behaves differently on unix and on windows.

windows:
  * The <Unmap> binding isn't fired when the popup
dissapears, which includes when the user doesn't select
one of the menu items.
  * All processing of the script stops as soon as the
popup is displayed. The script continues where it left
off after the popup dissapears.

unix:
  * Here the <Unmap> binding actually gets fired when
the popup dissapears.
  * Processing of the script continues after the popup
is shown. The rest of the script doesn't wait for the
popup to dissapear. 

For more information see
http://mini.net/tcl/3713

Rohan Pall
http://www.RohanPall.com
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-21 19:04:31:

Serhiy, many thanks! Merged into main, core-9-0-branch, and core-8-6-branch by commits [300c5273], [5f59d4ab], and [6a317f5f].


serhiy.storchaka added on 2026-09-22 17:39:13:

Still the case in 9.1b1, checked on X11 and on Windows 11.

On Windows and macOS the menu is displayed by the system, which runs its own event loop: tk_popup returns only when the menu is unposted again, and the Tk window of the menu is never mapped, so it generates no <Map> or <Unmap> events. This cannot be changed without replacing the native menus, so I documented it on branch doc-popup-platform in [a2b23a5104].


eb303 added on 2010-06-23 14:59:37:
Probably beating a dead horse here, but I just stumbled on this problem today. Here is a script reproducing it:
------------
menu .m
.m add command -label Test -command { puts "Item selected" }
bind .m <Unmap> { puts "Menu unmapped" }

proc post_menu {x y} {
  puts "tk_popup called"
  tk_popup .m $x $y
  puts "tk_popup returned"
}

bind . <1> { post_menu %X %Y }
------------
Just run the script and click on the window, then select the menu item. Here is what is printed on Linux:
tk_popup called
tk_popup returned
(Actual menu item selection occurs here)
Menu unmapped
Item selected
And here is what is printed on Windows (and on the Mac by the way):
tk_popup called
(Actual menu item selection occurs here)
tk_popup returned
Item selected
So tk_popup only returns when the menu item has actually been selected here, while it returns immediatly on Linux. And the <Unmap> binding is never called on Windows or on the Mac.

Not really a big problem since there is a way to know when the menu has disappeared on all platforms, so it's easy to get the same behaviour everywhere. But the platform type has to be tested anyway to know how things should be handled.

hobbs added on 2002-10-03 04:33:37:
Logged In: YES 
user_id=72656

do you have a simple script that can display these behaviors 
for testing?