Tk Source Code

Artifact [56a6ada1]
Login

Artifact 56a6ada1c515ad5bf6238773fbb66efcf3024457402d11c851908c7cc21514cf:

Attachment "exercise2.tcl" to ticket [0008d6a6] added by bll 2020-09-26 16:53:10.
#! /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
raise .a .
bind .a <Destroy> {handleWindowDestruction %W}

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

proc handleWindowDestruction {W} {
	puts "Window $W exists: [winfo exists $W]"
after 10 [list h2]
}
proc h2 { } {
  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