TCL\TK Resize window : bind

旧城冷巷雨未停 提交于 2019-12-11 06:35:30

问题


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:


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.



来源:https://stackoverflow.com/questions/42702695/tcl-tk-resize-window-bind

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!