日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python tcl 控件_在Tkinter.Tcl()中使用Python函数

發布時間:2025/3/20 python 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python tcl 控件_在Tkinter.Tcl()中使用Python函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

>我有一堆Python函數.我們稱他們為foo,bar和baz.它們接受可變數量的字符串參數,并執行其他復雜的操作(如訪問網絡).

>我希望“用戶”(讓我們假設他只熟悉Tcl)使用這些函數在Tcl中編寫腳本.

以下是用戶可以提出的示例(取自Macports):

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 && \

${qt_dir}/bin/qmake -spec ${qt_dir}/mkspecs/macx-g++ -macx \

-o Makefile python.pro"

}

}

}

這里,variant_issset,reinplace等(除了Tcl builtins)實現為Python函數. if,foreach,set等等是正常的Tcl結構. post-configure是一個Python函數,它接受一個Tcl代碼塊,以后可以執行(反過來顯然最終會調用上面提到的Python“函數”).

這可以用Python做嗎?如果是這樣,怎么樣?

來自Tkinter進口*; root = Tk(); root.tk.eval(‘puts [array get tcl_platform]’)是我所知道的唯一集成,顯然非常有限(更不用說它在mac上啟動X11服務器的事實).

解決方法:

通過一些實驗,我發現你可以做這樣的事情來創建一個tcl解釋器,注冊一個python命令,并從Tcl調用它:

import Tkinter

# create the tcl interpreter

tcl = Tkinter.Tcl()

# define a python function

def pycommand(*args):

print "pycommand args:", ", ".join(args)

# register it as a tcl command:

tcl_command_name = "pycommand"

python_function = pycommand

cmd = tcl.createcommand(tcl_command_name, python_function)

# call it, and print the results:

result = tcl.eval("pycommand one two three")

print "tcl result:", result

當我運行上面的代碼時,我得到:

$python2.5 /tmp/example.py

pycommand args: one, two, three

tcl result: None

標簽:python,dsl,tcl,integration

來源: https://codeday.me/bug/20190827/1740920.html

總結

以上是生活随笔為你收集整理的python tcl 控件_在Tkinter.Tcl()中使用Python函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。