Tk Source Code

Artifact [35a7ec0b]
Login

Artifact 35a7ec0b754cfb51fdc3e29f8a760b2ab105f4ee892cdab150b279ec9305205d:

Attachment "exercise.tcl" to ticket [58418fbd] added by erikleunissen 2021-08-12 08:23:29.
#! /bin/sh
# If executed as a shell script, the next line replaces the shell \
exec tclsh "$0" ${1+"$@"}

# waits while letting events be processed
proc twait {duration} {
	set ::_twait 1; after $duration {unset ::_twait}
	vwait ::_twait
}

package require Tk
wm iconify .
toplevel .t
pack propagate .t 0
wm geometry .t 200x200+100+100
wm deiconify .t
twait 200
event generate .t <Motion> -warp 1 -x 50 -y 50 -when now
twait 200

proc handleEvent {event W X Y} {
	# after 1; # remedies the erratic misbehaviour
	set pointerWin [winfo containing $X $Y]
	puts "$event $W $X $Y |$pointerWin|"
}
bind all <Enter> {handleEvent <Enter> %W %X %Y}
bind all <Leave> {handleEvent <Leave> %W %X %Y}

# exercise withdrawing
while {[incr i] <= 5} {
	wm deiconify .t
	twait 200
	wm withdraw .t
	twait 200
}

exit

#
# If desired, compare and contrast with a similar situation without
# involvement of the window manager, using a "pack forget"/"pack" cycle.
#

pack [frame .t.f -bg green -width 50 -height 50] -side right
wm deiconify .t
twait 300
event generate .t.f <Motion> -warp 1 -x 20 -y 20 -when now
twait 200

set i 0
while {[incr i] <= 5} {
	pack forget .t.f
	twait 200
	pack .t.f -side right
	twait 200
}

exit