我無法從小部件傳播到父窗口的事件。我的意思是我有自己的命令紡紗器,和我的鼠標點擊頂層綁定退出應用程序tcl/tk小部件命令和綁定鼠標按鈕單擊衝突
spinbox .mask -command { remask this %d ; break }
bind . <ButtonRelease-1> { recopy this ; exit }
當我點擊紡紗器滾動按鈕時,應用程序退出所有的時間。 breakbox似乎在spinbox事件命令中不起作用。
上下鍵綁定也不起作用。
這裏是爲了方便完整的代碼
proc expand { name } {
upvar 2 $name what
uplevel "upvar 1 $name that"
foreach key [array names what] {
uplevel "upvar 0 that($key) $key"
}
}
proc remask { name { delta 0 } } {
expand $name
if {$delta == "up" } { set delta 1 }
if {$delta == "down"} { set delta -1 }
set delta [expr $delta < 0 ? -1 : $delta > 0 ? 1 : 0]
set date [clock add $date $delta $unit]
set file [clock format $date -format $mask -locale fr]
set test [file exists $file]
}
proc reunit { name } {
expand $name
set map {
%a days
%A days
%d days
%V weeks
%b months
%B months
%m months
%y years
%Y years
%g years
%G years
}
foreach {key value} $map {
if { [string first $key $mask] > 0 } {
set unit $value
break
}
}
}
proc recopy { name } {
expand $name
if {!$test} {
if [file exists $mask] {
file copy $mask $file
} else {
open $file w
}
}
}
array set map {
0 green
1 red
}
set taken 0
if {$argc > 1} {
set path [lindex $argv 0]
cd [file dirname $path]
} else {
set path "file_%Y%m%d.txt"
}
set this(mask) [file tail $path]
set this(file) $this(mask)
set this(date) [clock seconds]
set this(unit) days
set this(test) [file exists $this(file)]
reunit this
remask this
set posx [winfo pointerx .]
set posy [winfo pointery .]
set posx [expr $posx - 50]
set posy [expr $posy - 40]
wm title . "rename $this(mask)"
wm attributes . -toolwindow true
wm geometry . +$posx+$posy
spinbox .mask -textvariable this(file) -foreground $map($this(test)) -command { remask this %d ; break }
pack .mask -fill x -padx 20 -pady 5
grab .
bind . <ButtonRelease-1> { recopy this ; exit }
bind . <Key-Return> { recopy this ; exit }
bind . <ButtonRelease-3> { exit }
bind . <Key-Escape> { exit }
bind . <MouseWheel> { remask this %D ; .mask configure -foreground $map($this(test)) }
bind . <Key-plus> { remask this +1 ; .mask configure -foreground $map($this(test)) }
bind . <Key-Up> { remask this +1 ; .mask configure -foreground $map($this(test)) }
bind . <Key-minus> { remask this -1 ; .mask configure -foreground $map($this(test)) }
bind . <Key-Down> { remask this -1 ; .mask configure -foreground $map($this(test)) }
完美解釋很清楚,不僅僅是文件。感謝你我現在明白綁定標籤的東西。 – buzard
我忘記了bindtags的規範解釋在哪裏;它甚至可能在一本書中... –