Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with Alt-o binding to destroy a window

33 views
Skip to first unread message

Frank Storm

unread,
Jul 22, 2015, 11:17:51 AM7/22/15
to
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

unread,
Jul 22, 2015, 2:10:37 PM7/22/15
to
Hi

Change your proc "handleOk".

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

regards

Manfred

Francois Vogel

unread,
Jul 22, 2015, 2:58:55 PM7/22/15
to
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

unread,
Jul 23, 2015, 1:31:03 PM7/23/15
to
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 new messages