Tk Source Code

Artifact [f89883d8]
Login

Artifact f89883d85440f35c73dcce210d0b8561e47c7820f6a6be05babdd30ea59746da:

Attachment "exercise.tcl" to ticket [0008d6a6] added by erikleunissen 2020-09-24 07:35:12.
#! /usr/bin/tclsh

package require Tk
wm withdraw .


#
# Wait for a specified duration while allowing events to be processed
#
proc twait {duration} {
	set ::_twait 1; after $duration {unset ::_twait}
	vwait ::_twait
}

toplevel .a -bg yellow
wm deiconify .a
twait 200
bind .a <Destroy> {handleWindowDestruction %W}

proc getPointerWindow {} {
	return [winfo containing [winfo pointerx .] [winfo pointery .]]
}

proc handleWindowDestruction {W} {
	puts "Window $W exists: [winfo exists $W]"
	puts "Window containing mouse pointer: \"[getPointerWindow]\""
}

# Position the mouse pointer over toplevel .a
event generate .a <Motion> -warp 1 -x 50 -y 50 -when now
twait 5000; # excessively long, in order to satisfy the human eye.

destroy .a