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} {

  ..
..
..

}

2 Answers 2

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:

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

Comments

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.

Comments

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.