1

I use import tkinter to perform Tcl script.

Such as:

import tkinter
runTCL = tkinter.Tk()
runTCL.tk.eval('puts [info tclversion]')

The default Tcl lib installed in my Python3.5 is Tcl8.6.

What I intent to do is that access IXIA and automatically configure it by script.

The problem is the APIs provides by my IXIA (with IxOS4.10) only can be accessed by Tcl8.4 lib, newer versions are unacceptable.

I knew it might be easy in Unix-like system by using ./configure --with-tcltk-libs and something like that.

But how could i re-build my Python3.5 with Tcl8.4 lib when i import tkinter on my Windows-64bit machine?

Thanks in advance.

9
  • Please read python.org/download/mac/tcltk. You'll discover there that you can't change the Tk version without recompiling and relinking the _tkinter module in Python Commented Aug 28, 2017 at 8:11
  • @MohhamadHasham Yes, that's what i'm asking. I need to re-build and re-compiling my Python. But i have no idea how to do. Commented Aug 28, 2017 at 8:14
  • The problem is that you can't, as written in the docs.You have to think other way round. :-) Commented Aug 28, 2017 at 8:15
  • 2
    Tcl 8.4.0 is 15 years old at this point. Even the most recent point release is over 10 years old. I suspect it would be easier to modify your scripts than it would be to recompile back to a 10-15 year old version of Tcl. Commented Aug 28, 2017 at 12:03
  • @BryanOakley Exactly. But i don't think i have ability to modify these old version IXOS APIs & scripts. Thanks for the advice! :( Commented Aug 29, 2017 at 0:41

1 Answer 1

1

The simplest way may be to run the code to access the IXIA as a subprocess so that it can use Tcl 8.4 without disrupting the version used by Python (which would have a lot of other consequences). Now Tcl 8.4 is no longer supported at all, but the most recent version of Tcl is 8.4.20, and came out only a few years ago so it is largely compatible with current build systems. (You can get the 8.4.20 source code from SourceForge.)

When you are building Tcl, assuming you are targeting Unix, you can configure where it will install using the --prefix= option to configure; the default location is /usr/local (e.g., the tclsh8.4 binary goes in /usr/local/bin, the support libraries go in /usr/local/lib, the documentation goes in /usr/local/man, …). If you have Tcl packages elsewhere that you want to use, the TCLLIBPATH environment variable can be used to say where they are. Also, if you are running as a subprocess, you may want to tune the level of buffering used on standard output:

# The default with terminals is line. The default with pipes is full.
fconfigure stdout -buffering line

In general, you will probably be substituting runTCL.tk.eval in your Python code for printing the code to run to the subprocess pipe and reading the result back. There's going to be a need for a bit of work to make that work neatly, but that sort of thing has been discussed in other questions here. The only major complication is really that you're working with an unsupported version of the code for your subprocess.

Sign up to request clarification or add additional context in comments.

1 Comment

Very thankful to this subprocess solution, simpler than i thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.