2

how to pass more than one arguments to tcl proc using Tkinter. i want to pass 3 args to tcl proc tableParser from python proc validate_op which has 3 args...

from Tkinter import Tcl
import os

tcl = Tcl()

def validate_op(fetch, header, value):
    tcl.eval('source tcl_proc.tcl') 
    tcl.eval('set op [tableParser $fetch $header $value]') <<<<< not working



proc tableParser { result_col args} {

  ..
..
..

}
shivsn
  • 7,680
  • 1
  • 26
  • 33

2 Answers2

1

The simplest way to handle this is to use the _stringify function in the Tkinter module.

def validate_op(fetch, header, value):
    tcl.eval('source tcl_proc.tcl') 
    f = tkinter._stringify(fetch)
    h = tkinter._stringify(header)
    v = tkinter._stringify(value)
    tcl.eval('set op [tableParser %(f)s %(h)s %(v)s]' % locals())

These two questions, while not answering your question, were useful in answering it:

Community
  • 1
  • 1
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
0

If you do not insist on eval, you can also do it like this:

def validate_op(fetch, header, value):
    tcl.eval('source tcl_proc.tcl')
    # create a Tcl string variable op to hold the result
    op = tkinter.StringVar(name='op')
    # call the Tcl code and store the result in the string var
    op.set(tcl.call('tableParser', fetch, header, value))

If your tableParser returns a handle to some expensive to serialize object, this is probably not a good idea, as it involves a conversion to string, which is avoided in the eval case. But if you just need to get a string back, this is just fine and you do not need to deal with the _stringify function mentioned in Donals answer.

schlenk
  • 7,002
  • 1
  • 25
  • 29