pyqt4 + 单选按钮
我有15个函数(def),还有15个单选按钮(p1, p2, p3……p15),另外还有一个QPush按钮。当我想用第一个函数时,我选择“p1”,然后点击我的QPush按钮,这样就能使用这个函数。为什么我需要这样做呢?因为我需要处理文本,我会在文本编辑器中打开一个文本,然后对它进行处理,但我只想通过单选按钮来使用一个函数。
比如说:
self.radioButton_1 = QRadioButton(self.Processing)
self.radioButton_1.setGeometry(QRect(520, 200, 50, 22))
self.radioButton_1.setObjectName(_fromUtf8("radioButton_1"))
self.radioButton_1.setText(QApplication.translate("Form", "P1", None, QApplication.UnicodeUTF8))
self.processLineButton = QPushButton(self.Processing)
self.processLineButton.setGeometry(QRect(800, 100, 100, 37))
self.processLineButton.setText(QApplication.translate("None","Process", None, QApplication.UnicodeUTF8))
还有
def example(exampless):
example = []
for exx in exampless:
es = re.findall("\.{3}!", exx)
if es:
example = example + [exx]
#endif
#endfor
self.TextProcess.setPlainText(example)
1 个回答
1
首先,你需要找到被选中的单选按钮,然后你就可以运行与那个按钮关联的函数,像这样:
for radioButton in self.findChildren(QtGui.QRadioButton):
if radioButton.isChecked():
radioButtonText = radioButton.text()
print "Radio Button Selected: ", radioButtonText
if radioButtonText == "example":
example(args)