f



Tkinter: different results from the same tcl script

Hello,
in mixed python-tcl programming I found the following different 
behaviours of the same tcl script.

If I type manually in the python interpreter the following lines

 >>> from Tkinter import *
 >>> w = Tk()
 >>> w.tk.evalfile('my_tcl_script.tcl')

where my_tcl_script.tcl is

    #!/bin/sh
    package require Tk
    wm withdraw .
    toplevel .root
    wm title .root "My title"

I obtain one toplevel window with title "My title", as expected.


The same result is obtained with the tcl shell command

% wish my_tcl_script.tcl


Now, I wish to run the same instructions from a python script. So, I 
written the following script

    from time import *
    from Tkinter import *
    w = Tk()
    w.tk.evalfile('my_tcl_script.tcl')
    sleep(3)

I expected to see the same toplevel window for 3 seconds, but the result 
of this python script is nothing, no window appears.

If anybody can explain the different behaviour and how to normalize it 
with the correct one, I will be very glad. Thank you in advance.


F. Pollastri
0
pollastri (4)
6/26/2007 8:06:16 AM
comp.lang.python 77058 articles. 6 followers. Post Follow

1 Replies
402 Views

Similar Articles

[PageSpeed] 58

On Jun 26, 1:06 am, Fabrizio Pollastri <pollas...@iriti.cnr.it> wrote:
> Hello,
> in mixed python-tcl programming I found the following different
> behaviours of the same tcl script.
>
> If I type manually in the python interpreter the following lines
>
>  >>> from Tkinter import *
>  >>> w = Tk()
>  >>> w.tk.evalfile('my_tcl_script.tcl')
>
> where my_tcl_script.tcl is
>
>     #!/bin/sh
>     package require Tk
>     wm withdraw .
>     toplevel .root
>     wm title .root "My title"
>
> I obtain one toplevel window with title "My title", as expected.
>
> The same result is obtained with the tcl shell command
>
> % wish my_tcl_script.tcl
>
> Now, I wish to run the same instructions from a python script. So, I
> written the following script
>
>     from time import *
>     from Tkinter import *
>     w = Tk()
>     w.tk.evalfile('my_tcl_script.tcl')
>     sleep(3)
>
> I expected to see the same toplevel window for 3 seconds, but the result
> of this python script is nothing, no window appears.
>
> If anybody can explain the different behaviour and how to normalize it
> with the correct one, I will be very glad. Thank you in advance.
>
> F. Pollastri

You need a call to `w.mainloop()`

w=Tk()
w.after(3000, lambda: w.quit())
w.mainloop()

~Sean

0
half.italian (252)
6/26/2007 8:36:13 AM
Reply: