Tkinter: different results from the same tcl script

half.italian at gmail.com half.italian at gmail.com
Tue Jun 26 10:36:13 CEST 2007


On Jun 26, 1:06 am, Fabrizio Pollastri <pollas... at 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




More information about the Python-list mailing list