title: Using Python functions in Tkinter.Tcl()
body: <ol>
  <li><p>I have a bunch of Python functions. Let's call them <code>foo</code>, <code>bar</code> and <code>baz</code>. They accept variable number of string arguments and does other sophisticated things (like accessing the network).</p></li>
  <li><p>I want the "user" (let's assume he is only familiar with Tcl) to write  scripts in Tcl using those functions.</p></li>
  </ol>
  
  <p>Here's an example (taken from <a href="http://py26-pyqt4.darwinports.com/dports/python/py26-pyqt4/Portfile" rel="nofollow noreferrer">Macports</a>) that user can come up with:</p>
  
  <pre><code>post-configure {
      if {[variant_isset universal]} {
          set conflags ""
          foreach arch ${configure.universal_archs} {
              if {${arch} == "i386"} {append conflags "x86 "} else {
                  if {${arch} == "ppc64"} {append conflags "ppc_64 "} else {
                      append conflags ${arch} " "
                  }
              }
          }
  
          set profiles [exec find ${worksrcpath} -name "*.pro"]
          foreach profile ${profiles} {
              reinplace -E "s|^(CONFIG\[ \\t].*)|\\1 ${conflags}|" ${profile}
  
              # Cures an isolated case
              system "cd ${worksrcpath}/designer &amp;&amp; \
                      ${qt_dir}/bin/qmake -spec ${qt_dir}/mkspecs/macx-g++ -macx \
                      -o Makefile python.pro"
          }
      }
  }
  </code></pre>
  
  <p>Here, <code>variant_issset</code>, <code>reinplace</code> are so on (other than Tcl builtins) are implemented as Python functions. <code>if</code>, <code>foreach</code>, <code>set</code>, etc.. are normal Tcl constructs. <code>post-configure</code> is a Python function that accepts, well, a Tcl code block that can later be executed (which in turns would obviously end up calling the above mentioned Python "functions").</p>
  
  <p>Is this possible to do in Python? If so, how?</p>
  
  <p><code>from Tkinter import *; root= Tk(); root.tk.eval('puts [array get tcl_platform]')</code> is the only integration I know of, which is obviously very limited (not to mention the fact that it starts up X11 server on mac).</p>