2016-06-17 4 views
2

Tkinterを使用して複数の引数をtcl procに渡す方法。私はこれを処理する最も簡単な方法は、Tkinterのモジュールで_stringify機能を使用することですPythonは、Tkinterを使用して複数の引数をtcl procに渡します。tcl.eval

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

    .. 
.. 
.. 

} 

答えて

1

... 3つの引数を持っているのpythonのproc validate_opからのproc tableParserをTCLする3つの引数を渡したいです。

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()) 

これら二つの質問、あなたの質問に答えていない間は、それに答えるに有用であった:

0

あなたはevalを主張していない場合は、次のようにすることもできます:

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)) 

tableParserがオブジェクトをシリアライズするために高価なハンドルを返す場合は、文字列への変換が含まれるため、これはお勧めできません。しかし、文字列を取得するだけでよい場合、これは問題なく、Donalsの答えに記載されている_stringify関数を処理する必要はありません。

関連する問題