2017-03-09 42 views
0

我有問題,當我調整我的窗口,我不明白爲什麼,當我移動我的窗口.我的另一個窗口創建與.c bind cir <1> [list window %x %y]不要跟着我的窗口. 我相信,已經使用<Configure>作爲選項,但我不知道如何爲您的幫助下TCL TK調整窗口:綁定

我的代碼做

感謝:

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

一般來說,這是壞的GUI設計製作WH ole羣組的窗口移動爲一個;它混淆了用戶。這就是說......

<Configure>事件被髮送到時,它是「重新配置」窗口小部件,這主要是這些天意味着它的位置相對於其父和大小被改變。您必須使用主bind命令,並且如果bind爲頂層,則需要記住頂層還默認偵聽由其非頂層子項生成的事件;你通常需要一些過濾。

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

一旦你有你想要的過濾的事件,計算幾何更新與wm geometry應用它們。

+0

謝謝@DonalFellows迴應 – Mkn