Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Problem with Alt-o binding to destroy a window

瀏覽次數:33 次
跳到第一則未讀訊息

Frank Storm

未讀,
2015年7月22日 上午11:17:512015/7/22
收件者:
Hi,

I have got a small problem with the binding of the shortcut Alt-o to
close a window.

Here is the example code:

--- snip ---

proc handleOk {w} {

destroy $w
}


set w .sub_window

toplevel $w -class Dialog
wm title $w "Test Window"

button $w.button -text "OK" -underline 0 \
-command [list handleOk $w]
pack $w.button

bind $w <Escape> [list handleOk $w]
bind $w <Alt-KeyPress-o> [list handleOk $w]

--- snip ---

If I press Escape the window closes. If I press Alt-o the window closes
but I get the following error message in addition:

bad window path name ".sub_window"
bad window path name ".sub_window"
while executing
"winfo class $w"
(procedure "tk::TraverseToMenu" line 6)
invoked from within
"tk::TraverseToMenu .sub_window o"
(command bound to event)

I would suppose that there is a sanity check missing wether $w still
exists. (It is interesting that there is this difference between Escape
and Alt-o.)
The problem is in Tcl/Tk 8.4, 8.5, and the latest 8.6.4.


Best regards,
Frank



--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

Manfred

未讀,
2015年7月22日 下午2:10:372015/7/22
收件者:
Hi

Change your proc "handleOk".

proc handleOk {w} {
after 0 "destroy $w"
}

regards

Manfred

Francois Vogel

未讀,
2015年7月22日 下午2:58:552015/7/22
收件者:
Frank Storm a écrit le 22/07/2015 17:17 :
> I have got a small problem with the binding of the shortcut Alt-o to
> close a window.

http://core.tcl.tk/tk/tktview/1236306fffffffffffff

F.

Frank Storm

未讀,
2015年7月23日 下午1:31:032015/7/23
收件者:
Hi Manfred, hi Francois,

thanks for the hints. Meanwhile I had fixed this by duplicating the
original Tk function and adding a "winfo exist". But I think the "after
0" is the better fix.
0 則新訊息