Lightning
EuroTcl2018
Talk
Munich
Version 1.7
July 2018
Convert a Tcl script of any size into a valid Python script in just two minutes.
hello.tcl
puts"Greetings from Tcl [info patchlevel]"
> tclsh hello.tclGreetings from Tcl 8.6.7
Let's look at our Python installation.
> dir D:\Python36… 2017-01-24 06:06 python.exe… 2017-08-07 16:34 <DIR> tcl …
> dir D:\Python36\tcl… 2017-08-07 16:35 <DIR> tcl8.6… 2017-08-07 16:35 <DIR> tk8.6 …
Because of Tk, which Python provides via its
Tk interface package:
tkinter
Write a Python wrapper: hello.py
importsys ;importtkinter"Greetings from Python {0}.{1}.{2}".format(*sys.version_info))gui= tkinter.Tk() gui.tk.eval(open(',hello.tcl''r').read())# if a Tk application, add:gui.mainloop()
> python3 hello.pyGreetings from Python 3.6.0Greetings from Tcl 8.6.7
Works for Python 2, if you capitalize Tkinter
and
use print statements.
{expand}"Team Tcl"
{*}"Team Tcl"
importTkintergui= Tkinter.Tk() gui.tk.eval(open('hello.tcl','r').read())ifFalse: gui.mainloop()
> python2 hello2.py Greetings from Tcl 8.5.15
importtkintergui= tkinter.Tk() gui.tk.eval(open('hello.tcl','r').read())ifFalse: gui.mainloop()
> python3 hello3.py Greetings from Tcl 8.6.6