2016-06-17 15 views
2

如何使用Tkinter將多個參數傳遞給tcl proc。我想通過3個參數傳遞給TCL從具有3個ARGS蟒蛇PROC validate_op PROC tableParser ...Python將超過一個參數傳遞給tcl proc使用Tkinter 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

來處理這個最簡單的方法是使用_stringify功能Tkinter的模塊中。

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返回一個昂貴的序列化對象的句柄,這可能不是一個好主意,因爲它涉及到字符串的轉換,這在eval情況下可以避免。但是如果你只需要返回一個字符串,這就好了,你不需要處理Donals答案中提到的_stringify函數。