首页 > 代码库 > pyqt 简单判断指定的内容强度(比如帐号)

pyqt 简单判断指定的内容强度(比如帐号)

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

# python:2.x

__author__ = ‘Administrator‘

 

from PyQt4.QtGui import *

from PyQt4.Qt import *

from PyQt4.QtCore import *

from pw import Ui_Form

#正则表达式检测密码格式

import sys

#时间关系,我只对一个地方帐号进行操作,其他类似

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

class Example(QDialog,Ui_Form):

    def __init__(self,parent=None):

        super(Example, self).__init__(parent)

        self.setupUi(self)

        self.readlineaccpe.setReadOnly(False)

        self.accpet.setEnabled(True)

        username=QRegExp(‘^[a-zA-Z][a-zA-Z0-9_]{6,12}‘)#以字母开头

        self.readlineaccpe.setValidator(QRegExpValidator(username,self))

        self.accpet.clicked.connect(self.bools)

    def bools(self):

        pw=self.readlineaccpe.text()

        if pw.isEmpty():

            self.tip.setText(u‘帐号为空‘)

            self.tip.setStyleSheet("color: rgb(255, 78, 25);")

        else:

            if len(pw)<6:

                self.tip.setText(u‘帐号过短‘)

            elif 6<=len(pw)<=9:

                self.tip.setText(u‘帐号中级‘)

            else:

                self.tip.setText(u‘帐号强‘)

 

 

app =QApplication(sys.argv)

x = Example()

x.show()

sys.exit(app.exec_())

 如图: