tcl是ToolCommandLanguage的首字母缩写,发展至今,目前使用较多的,可能是以下几个领域,altair的HyperWork产品、IC行业,Python,perl,haskell等语言使用作为GUI库。用户少那么弊端就很明显,对应的交流就少,缺少维护,缺少开源社区,反之对应的语言是什么呢,心中都有个答案,Python,是吧,又不是自己造轮子,gitclone一下方便快捷。Python,既然发展得如此迅猛,tcl如何搭上这艘快船呢,他提供了一个关键的函数,exec,使用起来也是很简单。最重要的是,将python.exe的目录置为当前。再就是你调用的包,包含在当前解释器。内网的小伙伴,anaconda安排上,解决大部分模块安装问题直接上代码,exec调用Python文件#Pythondefadd(a,b):returna+bsum=add(10,20)print(sum)#tclsetALTAIR_HOME[hm_info-appinfoALTAIR_HOME]setpython_s_dir"/hwsolvers/common/python/python3.4/win64"setpython_dir[format$ALTAIR_HOME%s$python_s_dir]cd$python_dirsetscriptsDir[filedir[infoscript]]setsum[execpython[filejoin$scriptsDiradd].py]puts$sumPython传递参数基于sys模块#Python文件内容importsysdefadd(a,b):returnint(a)+int(b)sum=add(sys.argv[1],sys.argv[2])print(sum)#tcl文件内容setALTAIR_HOME[hm_info-appinfoALTAIR_HOME]setpython_s_dir"/hwsolvers/common/python/python3.4/win64"setpython_dir[format$ALTAIR_HOME%s$python_s_dir]cd$python_dirsetsum[execpythonadd1.py5010]puts$sum通过捕获标准输出获取数据exec直接运行Python脚本setpython_script{importnumpyasnprandom_numbers=np.random.randn(100)print(random_numbers)}cd"D:/Users/jintian/anaconda3"setresult[execpython<<$python_script]puts"$result"GUI界面运行setpython_script{fromPyQt6.QtCoreimportQDateTime,Qt,QTimerfromPyQt6.QtWidgetsimport(QApplication,QCheckBox,QComboBox,QDateTimeEdit,QDial,QDialog,QGridLayout,QGroupBox,QHBoxLayout,QLabel,QLineEdit,QProgressBar,QPushButton,QRadioButton,QScrollBar,QSizePolicy,QSlider,QSpinBox,QStyleFactory,QTableWidget,QTabWidget,QTextEdit,QVBoxLayout,QWidget)classWidgetGallery(QDialog):def__init__(self,parent=None):super(WidgetGallery,self).__init__(parent)self.originalPalette=QApplication.palette()styleComboBox=QComboBox()styleComboBox.addItems(QStyleFactory.keys())styleLabel=QLabel("&Style:")styleLabel.setBuddy(styleComboBox)self.useStylePaletteCheckBox=QCheckBox("&Usestyle'sstandardpalette")self.useStylePaletteCheckBox.setChecked(True)disableWidgetsCheckBox=QCheckBox("&Disablewidgets")self.createTopLeftGroupBox()QApplication.processEvents()self.createTopRightGroupBox()QApplication.processEvents()self.createBottomLeftTabWidget()QApplication.processEvents()self.createBottomRightGroupBox()QApplication.processEvents()self.createProgressBar()QApplication.processEvents()styleComboBox.textActivated.connect(self.changeStyle)self.useStylePaletteCheckBox.toggled.connect(self.changePalette)disableWidgetsCheckBox.toggled.connect(self.topLeftGroupBox.setDisabled)disableWidgetsCheckBox.toggled.connect(self.topRightGroupBox.setDisabled)disableWidgetsCheckBox.toggled.connect(self.bottomLeftTabWidget.setDisabled)disableWidgetsCheckBox.toggled.connect(self.bottomRightGroupBox.setDisabled)topLayout=QHBoxLayout()topLayout.addWidget(styleLabel)topLayout.addWidget(styleComboBox)topLayout.addStretch(1)topLayout.addWidget(self.useStylePaletteCheckBox)topLayout.addWidget(disableWidgetsCheckBox)mainLayout=QGridLayout()mainLayout.addLayout(topLayout,0,0,1,2)mainLayout.addWidget(self.topLeftGroupBox,1,0)mainLayout.addWidget(self.topRightGroupBox,1,1)mainLayout.addWidget(self.bottomLeftTabWidget,2,0)mainLayout.addWidget(self.bottomRightGroupBox,2,1)mainLayout.addWidget(self.progressBar,3,0,1,2)mainLayout.setRowStretch(1,1)mainLayout.setRowStretch(2,1)mainLayout.setColumnStretch(0,1)mainLayout.setColumnStretch(1,1)self.setLayout(mainLayout)self.setWindowTitle("Styles")self.changeStyle('Windows')defchangeStyle(self,styleName):QApplication.setStyle(QStyleFactory.create(styleName))self.changePalette()defchangePalette(self):if(self.useStylePaletteCheckBox.isChecked()):QApplication.setPalette(QApplication.style().standardPalette())else:QApplication.setPalette(self.originalPalette)defadvanceProgressBar(self):curVal=self.progressBar.value()maxVal=self.progressBar.maximum()self.progressBar.setValue(curVal+(maxVal-curVal)//100)defcreateTopLeftGroupBox(self):self.topLeftGroupBox=QGroupBox("Group1")radioButton1=QRadioButton("Radiobutton1")radioButton2=QRadioButton("Radiobutton2")radioButton3=QRadioButton("Radiobutton3")radioButton1.setChecked(True)checkBox=QCheckBox("Tri-statecheckbox")checkBox.setTristate(True)checkBox.setCheckState(Qt.CheckState.PartiallyChecked)layout=QVBoxLayout()layout.addWidget(radioButton1)layout.addWidget(radioButton2)layout.addWidget(radioButton3)layout.addWidget(checkBox)layout.addStretch(1)self.topLeftGroupBox.setLayout(layout)defcreateTopRightGroupBox(self):self.topRightGroupBox=QGroupBox("Group2")defaultPushButton=QPushButton("DefaultPushButton")defaultPushButton.setDefault(True)togglePushButton=QPushButton("TogglePushButton")togglePushButton.setCheckable(True)togglePushButton.setChecked(True)flatPushButton=QPushButton("FlatPushButton")flatPushButton.setFlat(True)layout=QVBoxLayout()layout.addWidget(defaultPushButton)layout.addWidget(togglePushButton)layout.addWidget(flatPushButton)layout.addStretch(1)self.topRightGroupBox.setLayout(layout)defcreateBottomLeftTabWidget(self):self.bottomLeftTabWidget=QTabWidget()self.bottomLeftTabWidget.setSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Ignored)tab1=QWidget()tableWidget=QTableWidget(10,10)tab1hbox=QHBoxLayout()tab1hbox.setContentsMargins(5,5,5,5)tab1hbox.addWidget(tableWidget)tab1.setLayout(tab1hbox)tab2=QWidget()textEdit=QTextEdit()textEdit.setPlainText("Twinkle,twinkle,littlestar,\n""HowIwonderwhatyouare.\n""Upabovetheworldsohigh,\n""Likeadiamondinthesky.\n""Twinkle,twinkle,littlestar,\n""HowIwonderwhatyouare!\n")tab2hbox=QHBoxLayout()tab2hbox.setContentsMargins(5,5,5,5)tab2hbox.addWidget(textEdit)tab2.setLayout(tab2hbox)self.bottomLeftTabWidget.addTab(tab1,"&Table")self.bottomLeftTabWidget.addTab(tab2,"Text&Edit")defcreateBottomRightGroupBox(self):self.bottomRightGroupBox=QGroupBox("Group3")self.bottomRightGroupBox.setCheckable(True)self.bottomRightGroupBox.setChecked(True)lineEdit=QLineEdit('s3cRe7')lineEdit.setEchoMode(QLineEdit.EchoMode.Password)spinBox=QSpinBox(self.bottomRightGroupBox)spinBox.setValue(50)dateTimeEdit=QDateTimeEdit(self.bottomRightGroupBox)dateTimeEdit.setDateTime(QDateTime.currentDateTime())slider=QSlider(Qt.Orientation.Horizontal,self.bottomRightGroupBox)slider.setValue(40)scrollBar=QScrollBar(Qt.Orientation.Horizontal,self.bottomRightGroupBox)scrollBar.setValue(60)dial=QDial(self.bottomRightGroupBox)dial.setValue(30)dial.setNotchesVisible(True)layout=QGridLayout()layout.addWidget(lineEdit,0,0,1,2)layout.addWidget(spinBox,1,0,1,2)layout.addWidget(dateTimeEdit,2,0,1,2)layout.addWidget(slider,3,0)layout.addWidget(scrollBar,4,0)layout.addWidget(dial,3,1,2,1)layout.setRowStretch(5,1)self.bottomRightGroupBox.setLayout(layout)defcreateProgressBar(self):self.progressBar=QProgressBar()self.progressBar.setRange(0,10000)self.progressBar.setValue(0)timer=QTimer(self)timer.timeout.connect(self.advanceProgressBar)timer.start(1000)if__name__=='__main__':importsysapp=QApplication(sys.argv)gallery=WidgetGallery()gallery.show()sys.exit(app.exec())}cd"D:/Users/jintian/anaconda3"setresult[execpython<<$python_script&]拓展训练,如何使用tcl调取Python,对网格节点进行聚类分析,留给大家了,Python能够基于HyperWork平台干哪些有趣的事情,也交由大家探索了。看到这里了点点关注吧来源:TodayCAEer