python - pyqt4 + 单选按钮

标签 python qt radio-button pyqt pyqt4

我有 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/

相关文章:

Python邮箱编码错误

python - Tensorflow中如何使用多个汇总集合?

c++ - 在 QTableView 的自定义模型中添加和删除项目

c++ - 从计算机向计算机发送 XML 数据 - Qt

c++ - Linux 上的 Qt Phonon - 没有这样的文件或目录

android - 选择某个RadioButton时如何使UI组件消失

html - Checkbox/radio in li 元素 float right issue Firefox

java - 提取 GroupButton 值

Python 3.3 和在 Mac 上安装 PyOpenSSL

python - 使用 OutOfBoundsDatetime 儒略历到公历日期