首页 > 代码库 > pyqt单选,复选等例子学习

pyqt单选,复选等例子学习

# -*- coding: utf-8 -*-

# python:2.x

__author__ = ‘Administrator‘

 

from PyQt4.QtGui import *

from PyQt4.Qt import *

from PyQt4.QtCore import *

from check1 import Ui_Dialog

from check2 import Ui_Dialog1

from check3 import Ui_Dialog2

 

import sys

QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8"))

class Example(QDialog,Ui_Dialog):

    def __init__(self,parent=None):

        super(Example, self).__init__(parent)

        self.setupUi(self)

 

        self._3=_3()

        self._3.show()

        self.c1.toggled.connect(self.c01)

 

        #为了时间,我只对其中1个复选框进行操作

        self.c1_1.clicked.connect(self.checka)

    def checka(self,a):

        print dir(a)

        QMessageBox.information(self,u‘点击‘,‘%s‘%self.c1_1.text())

    def c01(self):

        if self.c1.isChecked()==False:

            self.c1_1.setChecked(False)

            self.c1_2.setChecked(False)

            self.c1_3.setChecked(False)

            self.c1_4.setChecked(False)

            self.c1_5.setChecked(False)

            self.c1_6.setChecked(False)

        else:

            self.c1_1.setChecked(1)

            self.c1_2.setChecked(1)

            self.c1_3.setChecked(1)

            self.c1_4.setChecked(1)

            self.c1_5.setChecked(1)

            self.c1_6.setChecked(1)

 

class _3(QWidget,Ui_Dialog2):

    def __init__(self,parent=None):

        super(_3, self).__init__(parent)

        self.setupUi(self)

        self.move(170,80)

        self.comboBox.addItem(‘a‘)

        self.comboBox.addItem(‘b‘)

        self.comboBox.addItem(‘c‘)

        self.comboBox.activated.connect(self.s1)

 

        self.comboBox.activated.connect(self.s2)

        self.appens()

    def appens(self):

        a=QStringList()

        for i in range(21):

            a.append(str(i))

            #print a.count()

            self.label_4.setText(str(a.count()))

    def s1(self,text):

        self.label_3.setText(unicode(self.comboBox.currentText()))

    def s2(self,text):#这边是我想对应选择指定的进行操作,代码很简单,只是个方法

        print str(text)

        if text==2:

            QMessageBox.information(self,u‘提示‘,self.comboBox.currentText())

 

        else:

            print ‘error:‘,self.comboBox.currentText()

 

app =QApplication(sys.argv)

x = Example()

x.show()

sys.exit(app.exec_())

 如图: