Tk Source Code

View Ticket
Login
Ticket UUID: 531658
Title: ButtonRelease on Grab Window
Type: Bug Version: obsolete: 8.3.4
Submitter: nobody Created on: 2002-03-19 00:22:30
Subsystem: 69. Events Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Pending Last Modified: 2026-09-23 12:49:02
Resolution: Works for Me Closed By:
    Closed on:
Description:
I have a problem with the ButtonRelease bind on a 
window that has the grab if I move off the window with 
the button depressed and then release it.
Platform: Windows 2000

Steps to reproduce:
1. Create a window:

    toplevel .testWindow -class Toplevel
    wm focusmodel .testWindow passive
    wm geometry .testWindow 406x312+254+250
    wm title .testWindow "Login"
    entry .testWindow.userId
    place .testWindow.userId -in .testWindow \
          -x 145 -y 80
    grab .testWindow
    # Done

NOTE: You must make sure the window has the grab.

2. Place the cursor in the entry widget and type
   the "123456789"

3. Hold down the LMB and highlight what you just typed.
   Without releasing the LMB, move the mouse over 
   to the Windows Desktop and then release the LMB.

4. Move the mouse back over the .testWindow. TK acts 
   like the LMB is still depressed. If you start
   typing with everything highlight, input appears to
   the left because it acts like you have the first
   character highlighted.
User Comments: serhiy.storchaka added on 2026-09-23 12:49:02:

Cannot reproduce on Windows 11, neither with Tk 9.1b1 nor with 8.6.18. With grab .t held, pressing in the entry, dragging onto the desktop and releasing the button there delivers the ButtonRelease to the entry and to the toplevel, and afterwards the state has no Button1 bit:

Press     .t.e state=0
B1-Motion .t.e state=256
Leave     .t.e state=256
Release   .t.e state=256
Enter     .t   state=0

TkPointerEvent() sets a mouse capture on the restrict window also when a grab is active (generic/tkPointer.c), so a release outside the application still arrives. The report is for 8.3.4 on Windows 2000.


hobbs added on 2004-09-10 13:38:32:
Logged In: YES 
user_id=72656

Related to patch #611615 that addressed this for dialogs.

eserte added on 2002-08-27 04:00:43:
Logged In: YES 
user_id=54935

Here's an even simpler example for this problem (tested on
FreeBSD):

wm geometry . 200x200
button .b
bind .b <ButtonPress-1>   {puts "press";  grab .}
bind .b <ButtonRelease-1> {puts "release";grab release .}
pack .b

Click on the button (you see "press" on stdout), move the
mouse away, and release the mouse button (you do _not_ see
"release" on stdout). If you go back to the button and
press-release the mouse, then the button stays depressed.