Tk Source Code

View Ticket
Login
Ticket UUID: 3279221
Title: Popup menu disappears immediately
Type: Patch Version: None
Submitter: danckaert Created on: 2011-04-07 10:54:57
Subsystem: 12. Unix Menus Assigned To: aku
Priority: 7 High Severity: Minor
Status: Closed Last Modified: 2014-02-06 21:25:46
Resolution: Fixed Closed By: aku
    Closed on: 2014-02-06 21:25:46
Description:
Consider the following code:

  pack [label .l -text label]
  menu .m
  .m add command -label foo
  bind .l <3> {after 500; tk_popup .m %X %Y}

Now, when right-clicking on the label, the popup menu appears but disappears immediately. The "after 500" is there to simulate some work that needs to be done before the menu can be drawn.

Investigation shows that the menu disappears when the mouse button is released before the menu is drawn. This is caused by the fact that, even though the menu is not yet drawn, the <ButtonRelease> event is directed to it, and it comes before the <Enter> event which sets the Priv(window) variable in menu.tcl.

I would propose to set Priv(window) also when the popup is drawn.

This seems correct since, when drawing a popup menu, you at least want it to stay visible initially, even when the mouse cursor is not over it (note that this behavior is also consistent with Windows).

See the attached patch, which solves this issue.
User Comments: aku added on 2014-02-06 21:25:46:
Patch reviewed and ok'd by jhobbs.

Tk 8.5 revision [b29e591648].
Committed.
Pushed.

Tk 8.6 revision [79c4b25313].
Committed.
Pushed.

danckaert added on 2011-04-07 17:54:58:

File Added - 407531: patch

Attachments: