1
votes

I have problem when I resize my window ,I don't understand why, when I move my window . my another window created with .c bind cir <1> [list window %x %y] do not follow my window . I believe that I've to use <Configure> as option, but I don't know how to do

Thanks for your help

My code below :

proc window {crx cry} {

set w1 .win
catch {destroy $w1}
toplevel $w1

wm minsize $w1 300 100
wm maxsize $w1 300 100

label $w1.l -text "$crx $cry"

pack $w1.l

}

wm state . zoomed

canvas .c -bg ivory

.c create oval 2 1.5 25 25 -fill #33FF00 -tag cir
.c create oval 30 30 50 50 -fill #33FF00 -tag cir1
.c create oval 60 60 90 90 -fill #33FF00 -tag cir2
.c create oval 90 90 130 130 -fill #33FF00 -tag cir3

pack .c -fill both -expand 1

.c bind cir <1> [list window %x %y]
.c bind cir1 <1> [list window %x %y]
.c bind cir2 <1> [list window %x %y]
.c bind cir3 <1> [list window %x %y]
1

1 Answers

4
votes

Generally speaking, it's bad GUI design to make a whole group of windows move as one; it confuses users. That said…

The <Configure> event is sent to a widget whenever it is “reconfigured”, which mostly these days means that its location relative to its parent and size are altered. You have to use the main bind command, and if you bind to a toplevel you need to remember that toplevels also listen to the events generated by their non-toplevel children by default; you usually need some filtering.

bind . <Configure> {
    if {"%W" eq [winfo toplevel %W]} {
        puts "reconfigured %W: (%x,%y) %wx%h"
    }
}

Once you have the filtered events you want, compute the updated geometries and apply them with wm geometry.