Tkinter: different results from the same tcl script

F

Fabrizio Pollastri

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

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
 
H

half.italian

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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top