TCL\TK 调整窗口大小:绑定 [英] TCL\TK Resize window : bind
问题描述
我在调整窗口大小时遇到问题,我不明白为什么,当我移动窗口 .
我用 .c bind cir <1> 创建的另一个窗口[列表窗口 %x %y]
不要跟随我的窗口 .
我相信我必须使用
作为选项,但我不知道该怎么做
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
感谢您的帮助
我的代码如下:
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]
推荐答案
一般来说,把一整组窗口作为一个整体移动是不好的GUI设计;它让用户感到困惑.也就是说……
Generally speaking, it's bad GUI design to make a whole group of windows move as one; it confuses users. That said…
<Configure>
事件在重新配置"时发送到小部件,如今这主要意味着它的位置相对于其父级和大小是改变了.你必须使用主要的 bind
命令,如果你 bind
到一个顶层,你需要记住,默认情况下,顶层也会监听由它们的非顶层子节点生成的事件;你通常需要一些过滤.
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"
}
}
一旦你有了你想要的过滤事件,计算更新的几何图形并用 wm geometry
应用它们.
Once you have the filtered events you want, compute the updated geometries and apply them with wm geometry
.
这篇关于TCL\TK 调整窗口大小:绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!