我有 15 个防御。我有 15 个单选按钮(p1、p2、p3.....p15)。我有 1 个 QPush 按钮。 当我想使用我的第一个定义时,我选择“p1”,单击我的 QPushButton,然后使用这个定义。为什么我需要它?因为我需要处理文本,所以我在文本编辑中打开文本并且需要处理它,但我只想使用单选按钮使用一个定义。 我该怎么做?
例如:
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)
最佳答案
首先,您需要找到选中的单选按钮,然后您可以运行分配给该按钮的功能,如下所示:
for radioButton in self.findChildren(QtGui.QRadioButton):
if radioButton.isChecked():
radioButtonText = radioButton.text()
print "Radio Button Selected: ", radioButtonText
if radioButtonText == "example":
example(args)
关于python - pyqt4 + 单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14987355/