Home > Archive > Tcl > December 2006 > Why I need to click twice to destroy a top level window?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Why I need to click twice to destroy a top level window?
|
|
| pheobe 2006-12-15, 4:14 am |
| hi, guys:
I wrote two files
a. tcl and b.tcl
in my a .tcl:
I wrote:
--------------------------------------------------
exec wish.exe b.tcl
--------------------------------------------------
in my b.tcl:
I wrote:
--------------------------------------------------------
set title "mode"
wm title . $title
frame .main -width 200 -height 300 -bg red
pack .main
tk_optionMenu .main.opt1 say_hello "hello" "hi" "haloha"
set say_hello "hello"
pack .main.opt1 -side top
set bot_frm [frame .main.frm]
pack $bot_frm -side bottom -fill x -expand yes
button $bot_frm.ok -text "Ok" -command "destroy_win"
button $bot_frm.cancel -text "Cancel" -command ""
pack $bot_frm.ok $bot_frm.cancel -side left -fill x -pady 5
#=======================
proc destroy_win {} {
#========================
destroy .
}
----------------------------------------------------------------------------
while when I run my a.tcl, the dialog appears. And I click "Ok", then
anther dialog appears, it's exactly the same dialog with the first one,
then I need to click "Ok" button on the newly generated dialog, and
then both of the two dialog disppear.
Why? Can anybody help me ?
By the way, even I replace 'destroy .' with "wm withdraw ." The same
thing will happen.
| |
| pheobe 2006-12-15, 4:14 am |
| Addtional info to supplement:
If I just source b.tcl in a single wish application, I click "Ok"
button, and then the dialog disppear. It works well. Yet what I need
to run wish in my a.tcl.
| |
| Ralf Fassel 2006-12-15, 8:10 am |
| * "pheobe" <pheobe.du@gmail.com>
| hi, guys:
| I wrote:
| --------------------------------------------------
| exec wish.exe b.tcl
| --------------------------------------------------
Is this the only contents of a.tcl? Or do you happen to have the code
from b.tcl also after that line in a.tcl? This would explain the
effect you describe...
R'
| |
| Bryan Oakley 2006-12-15, 8:10 am |
| pheobe wrote:
> hi, guys:
>
> I wrote two files
> a. tcl and b.tcl
>
> in my a .tcl:
>
> I wrote:
> --------------------------------------------------
> exec wish.exe b.tcl
> --------------------------------------------------
>
>
> in my b.tcl:
> I wrote:
> --------------------------------------------------------
> set title "mode"
> wm title . $title
>
> frame .main -width 200 -height 300 -bg red
> pack .main
> tk_optionMenu .main.opt1 say_hello "hello" "hi" "haloha"
> set say_hello "hello"
> pack .main.opt1 -side top
> set bot_frm [frame .main.frm]
> pack $bot_frm -side bottom -fill x -expand yes
>
> button $bot_frm.ok -text "Ok" -command "destroy_win"
> button $bot_frm.cancel -text "Cancel" -command ""
> pack $bot_frm.ok $bot_frm.cancel -side left -fill x -pady 5
>
> #=======================
> proc destroy_win {} {
> #========================
>
> destroy .
>
> }
>
>
> ----------------------------------------------------------------------------
>
>
>
> while when I run my a.tcl, the dialog appears. And I click "Ok", then
> anther dialog appears, it's exactly the same dialog with the first one,
> then I need to click "Ok" button on the newly generated dialog, and
> then both of the two dialog disppear.
>
What you say cannot happen with the code you posted. Are you absolutely
certain you have shown us exactly what is in both files?
Of course, you will get two windows, just not the two you describe. The
second window should be completely blank. With the code you presented
it's simply not possible for the second one to be "exactly the same
dialog with the first one".
| |
| Gerald W. Lester 2006-12-15, 8:10 am |
| Bryan Oakley wrote:
> pheobe wrote:
>
> What you say cannot happen with the code you posted. Are you absolutely
> certain you have shown us exactly what is in both files?
>
> Of course, you will get two windows, just not the two you describe. The
> second window should be completely blank. With the code you presented
> it's simply not possible for the second one to be "exactly the same
> dialog with the first one".
My guess:
a.tcl really reads:
exec wish.exe b.tcl
source b.tcl
This would duplicate the symptoms you describe.
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
| |
| Larry W. Virden 2006-12-15, 7:10 pm |
| Hey, if you want to email me, attaching file a and b to the email
message, I would be happy to look and see what I see. Also, what
platform are you using?
pheobe wrote:
> hi, guys:
>
> I wrote two files
> a. tcl and b.tcl
>
> in my a .tcl:
>
> I wrote:
> --------------------------------------------------
> exec wish.exe b.tcl
> --------------------------------------------------
>
>
> in my b.tcl:
> I wrote:
> --------------------------------------------------------
> set title "mode"
> wm title . $title
>
> frame .main -width 200 -height 300 -bg red
> pack .main
> tk_optionMenu .main.opt1 say_hello "hello" "hi" "haloha"
> set say_hello "hello"
> pack .main.opt1 -side top
> set bot_frm [frame .main.frm]
> pack $bot_frm -side bottom -fill x -expand yes
>
> button $bot_frm.ok -text "Ok" -command "destroy_win"
> button $bot_frm.cancel -text "Cancel" -command ""
> pack $bot_frm.ok $bot_frm.cancel -side left -fill x -pady 5
>
> #=======================
> proc destroy_win {} {
> #========================
>
> destroy .
>
> }
>
>
> ----------------------------------------------------------------------------
>
>
>
> while when I run my a.tcl, the dialog appears. And I click "Ok", then
> anther dialog appears, it's exactly the same dialog with the first one,
> then I need to click "Ok" button on the newly generated dialog, and
> then both of the two dialog disppear.
>
>
> Why? Can anybody help me ?
> By the way, even I replace 'destroy .' with "wm withdraw ." The same
> thing will happen.
| |
| pheobe 2006-12-17, 10:08 pm |
| Hi, my friend:
The files are exactly the two files I am runing, and there's no
other content.
Yet the difference is, I run a.tcl in my application not alone.
If I run this file alone, the dialog appears, I click "Ok" , then the
dialog dissapears, and only the empty wish dialog still exist.
But if this files is runing in my application, I click "OK", then
the exactlly same dialog appears instead of the empty wish dialog. I
click "Ok" again, then the dialog dissapears.
Cos I am doing a test, the simple two files are exactly what I
used in my application. My guess is, although the resluts are
different while I run a.tcl alone or run this file in my application,
it might be casued by the same reason: wish.exe is still running. But
I don''t know whether it's true and how to deal with it.
Can you give me more hint?
Best Regards
| |
| pheobe 2006-12-17, 10:08 pm |
| By the way:
exec wish.exe b.tcl
This sentence is the only line in my a.tcl file. Nothing else.
| |
| Ralf Fassel 2006-12-18, 4:16 am |
| * "pheobe" <pheobe.du@gmail.com>
| By the way:
|
| exec wish.exe b.tcl
Just a guess: 'exec' in TCL does not terminate the current process
like e.g. in sh or perl. 'exec' executes the command, waits for it to
finish *and then continues the current TCL script*. So yes, after the
'exec', the current 'wish' is still running, the exec'd wish is not.
R'
|
|
|
|
|