Tk Source Code

Artifact [09993442]
Login

Artifact 09993442b39ff39ca82225454dbfa3faab90e6ed2fad6afcad39b58f93b1b60b:

Attachment "manual-2182522.tcl" to ticket [2182522f] added by serhiy.storchaka 2026-10-08 18:43:27.
# Manual reproducer for Tk ticket 2182522: ttk::combobox fails to restore
# the grab when its list is closed by clicking another window of the application.
#
# Run with wish on X11.  Then:
#   1. Click the combobox in the "grabbed" window to open its list.
#   2. Close the list without selecting an item by clicking the "click here
#      to close the list" area above the combobox.  (Any place outside the
#      list but inside a Tk window works too.  On a classic X server a click
#      on the desktop works as well; under Xwayland it does not reach the
#      list, which then stays open.)
#   3. Watch the status line: it must say "grab: .tree1 (local)".
#      With the bug it says "grab: none" and the "Quit (must be blocked)"
#      button in the second window becomes usable.
#
# Closing the list by selecting an item does not show the bug, because the
# button is released before the grab is restored.

wm withdraw .
frame .tree1

toplevel .tree1.top
wm title .tree1.top "grabbed"
ttk::combobox .tree1.top.box -state readonly \
    -values {"Option 1" "Option 2" "Option 3"}
button .tree1.top.quit -text Quit -command exit
label .tree1.top.status -width 32 -anchor w
label .tree1.top.target -text "click here to close the list" \
    -relief groove -borderwidth 2 -padx 8 -pady 12 -background lightyellow
grid .tree1.top.target -padx 8 -pady 8 -sticky we
grid .tree1.top.box -padx 8 -pady 8 -sticky nwe
grid .tree1.top.quit -padx 8 -pady 8
grid .tree1.top.status -padx 8 -pady 8 -sticky we

toplevel .top2
wm title .top2 "outside the grab"
button .top2.quit -text "Quit (must be blocked)" \
    -command {puts "BUG: a window outside the grab got the click"; exit 1}
grid .top2.quit -padx 8 -pady 8

proc showGrab {} {
    set w [grab current]
    if {$w eq ""} {
	set text "grab: none  <-- BUG"
	set color red
    } else {
	set text "grab: $w ([grab status $w])"
	set color [expr {$w eq ".tree1" ? "dark green" : "black"}]
    }
    .tree1.top.status configure -text $text -foreground $color
    after 200 showGrab
}

update
grab .tree1
showGrab