Version 1 of Jittering toplevel

Updated 2005-07-09 21:35:52

if 0 {Richard Suchenwirth 2005-07-09 - There are several ways to catch the attention of a user to a window, e.g. an alert or dialog - flashing colors are sometimes used. One can also make a toplevel "jitter", i.e. move slightly to the left and bottom, and back again. One pixel is enough to catch attention, as windows usually (and thankfully!) stand still. I saw this effect in an ad on AOL's home page, and even though I'd hardly ever use it, in this Saturday breakfast fun project I wanted to code it - "because we can" :) Here it is, in bare-bones fashion. If you drag the window, it will snap back to its original position. }

 proc jitter {w {dt 200}} {
    if [winfo exists $w] {
        after $dt
        regexp {\+(\d+)\+(\d+)} [wm geometry $w] -> x y
        wm geometry $w +[expr $x+1]+[expr $x+1]
        update idletasks
        after $dt
        wm geometry $w +$x+$y
        after 1 [list jitter $w $dt]
    }
 }

#-- Testing

 pack [label .l -text "Jitter test"]
 jitter .
 bind . <Escape> {exec wish $argv0 &; exit}

if 0 {

MG July 9 2005 - Edited the after 1 ... line in the jitter proc, so that it also passes the time, $dt. Otherwise, using anything but the default only had an effect the first time, and was afterwards ignored.


Category Animation | Arts and crafts of Tcl-Tk programming }