【PyQt5-Qt Designer】按钮系列

时间:2022-02-05 17:57:38

【PyQt5-Qt Designer】按钮系列

复选框(QCheckBox)

效果如下:

【PyQt5-Qt Designer】按钮系列

参考:

https://zhuanlan.zhihu.com/p/30509947

完整代码:

from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QGridLayout,QCheckBox,QMessageBox)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import (QIcon,QFont,QPixmap)
import sys class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,200,200)
self.setWindowTitle("复选框")
gridLayout = QGridLayout()
self.btn = QPushButton("提交")
self.cb1 = QCheckBox("全选")
self.cb2 = QCheckBox("你是")
self.cb3 = QCheckBox("我的")
self.cb4 = QCheckBox("宝贝")
gridLayout.addWidget(self.cb1,0,0,1,1)
gridLayout.addWidget(self.cb2,1,0,1,1)
gridLayout.addWidget(self.cb3,2,0,1,1)
gridLayout.addWidget(self.cb4,3,0,1,1)
gridLayout.addWidget(self.btn,4,0,1,1)
self.setLayout(gridLayout) self.cb1.stateChanged.connect(self.changecb1)
self.cb2.stateChanged.connect(self.changecb2)
self.cb3.stateChanged.connect(self.changecb2)
self.cb4.stateChanged.connect(self.changecb2)
self.btn.clicked.connect(self.btnConfirm) def changecb1(self):
if self.cb1.checkState() == Qt.Checked:
self.cb2.setChecked(1)
self.cb3.setChecked(1)
self.cb4.setChecked(1)
elif self.cb1.checkState() == Qt.Unchecked:
self.cb2.setChecked(0)
self.cb3.setChecked(0)
self.cb4.setChecked(0) def changecb2(self):
if self.cb2.checkState() and self.cb3.checkState() and self.cb4.checkState():
self.cb1.setCheckState(1)
elif self.cb2.checkState() or self.cb3.checkState() or self.cb4.checkState():
# self.cb1.setTristate()
# self.cb1.setCheckState(Qt.PartiallyChecked)
self.cb1.setCheckState(0)
else:
self.cb1.setTristate(0)
self.cb1.setCheckState(Qt.Unchecked) def btnConfirm(self):
if self.cb1.checkState():
info = "你是我的宝贝"
elif self.cb2.checkState() and self.cb3.checkState():
info = "你是我的"
elif self.cb2.checkState() and self.cb4.checkState():
info = "你是宝贝"
elif self.cb3.checkState() and self.cb4.checkState():
info = "我的宝贝"
elif self.cb2.checkState():
info = "你是"
elif self.cb3.checkState():
info = "我的"
elif self.cb4.checkState():
info = "宝贝"
else:
info = "什么都没有选中啊。。。"
reply = QMessageBox.information(self,"消息框",info) if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

复选框(QCheckBox)

单选按钮(QRadioButton)

效果如下:

【PyQt5-Qt Designer】按钮系列

参考:

https://zhuanlan.zhihu.com/p/30708796

完整代码:

from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QGridLayout,QRadioButton,QMessageBox,QButtonGroup)
from PyQt5.QtCore import Qt
from PyQt5.QtGui import (QIcon,QFont,QPixmap)
import sys class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,200,200)
self.setWindowTitle("单选框")
gridLayout = QGridLayout()
self.btn = QPushButton("提交")
self.rb11 = QRadioButton("你是")
self.rb12 = QRadioButton("大美女")
self.rb21 = QRadioButton("我是")
self.rb22 = QRadioButton("大帅哥")
self.rb31 = QRadioButton("他是")
self.rb32 = QRadioButton("小屁孩")
gridLayout.addWidget(self.rb11,0,0,1,1)
gridLayout.addWidget(self.rb12,0,1,1,1)
gridLayout.addWidget(self.rb21,1,0,1,1)
gridLayout.addWidget(self.rb22,1,1,1,1)
gridLayout.addWidget(self.rb31,2,0,1,1)
gridLayout.addWidget(self.rb32,2,1,1,1)
gridLayout.addWidget(self.btn,3,0,1,2)
self.setLayout(gridLayout)
#建立了两个单选按钮分组,其中每个分组单选按钮是互斥的,在每个分组中分别选择一个单选按钮,然后提交就得到相应的信息了
#新建6个单选按钮。如果不增加分组,这个6个单选按钮是互斥的,因为单选按钮默认为autoExclusive(自动互斥)
#将单选按钮添加到分组中,同时分配一个id号。函数默认的id是-1 自动分配的ID保证为负数,从-2开始。 如果您正在分配自己的ID,请使用正值来避免冲突。
self.bg1 = QButtonGroup()
self.bg1.addButton(self.rb11,11)
self.bg1.addButton(self.rb21,21)
self.bg1.addButton(self.rb31,31)
self.bg2 = QButtonGroup()
self.bg2.addButton(self.rb12, 12)
self.bg2.addButton(self.rb22, 22)
self.bg2.addButton(self.rb32, 32) self.info1 = ""
self.info2 = ""
#在分组中点击给定按钮的时候会发出buttonClicked()信号,同时我们连接到rbclicked这个槽函数上
self.bg1.buttonClicked.connect(self.rb_clicked)
self.bg2.buttonClicked.connect(self.rb_clicked)
self.btn.clicked.connect(self.btn_submit) def rb_clicked(self):
sender = self.sender()
if sender == self.bg1:
if self.bg1.checkedId() == 11:
self.info1 = "你是"
elif self.bg1.checkedId() == 21:
self.info1 = "我是"
elif self.bg1.checkedId() == 31:
self.info1 = "他是"
else:
self.info1 = ""
elif sender == self.bg2:
if self.bg2.checkedId() == 12:
self.info2 = "大美女"
elif self.bg2.checkedId() == 22:
self.info2 = "大帅哥"
elif self.bg2.checkedId() == 32:
self.info2 = "小屁孩"
else:
self.info2 = "" def btn_submit(self):
if self.info1 == "" or self.info2 == "":
QMessageBox.information(self,"radioButton标题","你什么都没有选啊!")
else:
QMessageBox.information(self,"radioButton标题",self.info1+self.info2) if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

单选按钮(QRadioButton)

普通按钮(QPushButton) 按钮下拉选择

效果如下:

【PyQt5-Qt Designer】按钮系列

参考:

https://zhuanlan.zhihu.com/p/32239438

完整代码:

from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QGridLayout,QMenu,QMessageBox,QButtonGroup)
from PyQt5.QtCore import Qt,QTimer
from PyQt5.QtGui import (QIcon,QFont,QPixmap)
import sys,time class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,300,200)
self.setWindowTitle("下拉选择按钮+计时器")
gridLayout = QGridLayout()
self.btn1 = QPushButton("这是什么?")
self.btn2 = QPushButton("发送验证码")
menu = QMenu()
menu.addAction("我是")
menu.addSeparator()
menu.addAction("世界上")
menu.addSeparator()
menu.addAction("最帅的人")
menu.addSeparator()
self.btn1.setMenu(menu)
gridLayout.addWidget(self.btn1,0,0,1,1)
gridLayout.addWidget(self.btn2,0,1,1,1)
self.setLayout(gridLayout)
self.count = 10
self.btn2.clicked.connect(self.Verification_code)
self.time = QTimer()
self.time.setInterval(1000) #设置时间间隔为1000ms
self.time.timeout.connect(self.Refresh) def Verification_code(self):
if self.btn2.isEnabled():
self.time.start() #开始计时
self.btn2.setEnabled(0) #设置按钮为未激活状态 def Refresh(self):
if self.count >0:
self.btn2.setText(str(self.count)+"秒后重发")
self.count -= 1
else:
self.time.stop()
self.bt2.setEnabled(True) ##设置按钮为使能状态
self.bt2.setText('发送验证码')
self.count = 10 if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

QMenu()+QTimer()

补充 QTimer()计时器:

效果如下:

【PyQt5-Qt Designer】按钮系列

完整代码:

import time,sys
from PyQt5.QtCore import Qt,QTimer
from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QGridLayout,QMenu,QMessageBox,QButtonGroup,QLabel) class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle("Qtimer计时器案例")
gridLayout = QGridLayout()
self.btn1 = QPushButton("开始计时")
self.lb = QLabel("10s计时器,发送验证码")
gridLayout.addWidget(self.lb,0,0,1,1)
gridLayout.addWidget(self.btn1,1,0,1,1)
self.setLayout(gridLayout) self.btn1.clicked.connect(self.start_timer)
self.count = 10
self.timer = QTimer()
self.timer.setInterval(1000)
self.timer.timeout.connect(self.time_count) def start_timer(self):
if self.btn1.isEnabled():
self.timer.start()
self.btn1.setEnabled(0) def time_count(self):
if self.count>0:
self.lb.setText(str(self.count) + "秒后重发")
self.count-=1
else:
self.timer.stop()
self.btn1.setText('已发送验证码')
self.lb.setText('')
self.btn1.setEnabled(True)
self.count = 10 if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

QTimer()案例

工具按钮(QToolButton)

效果如下:

【PyQt5-Qt Designer】按钮系列

参考:

https://zhuanlan.zhihu.com/p/32407887

https://doc.qt.io/qt-5/qtoolbutton.html

完整代码:

from PyQt5.QtWidgets import (QApplication,QWidget,QMenu,QToolButton,QAction)
from PyQt5.QtCore import (Qt,QUrl)
from PyQt5.QtGui import (QIcon,QDesktopServices)
import sys class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,300,200)
self.setWindowTitle("工具按钮") self.tb = QToolButton(self)
self.tb.move(100,100)
self.tb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) #设置工具按钮类型:图标在文字旁边
# self.tb.setArrowType(Qt.DownArrow) #设置箭头图标
self.tb.setToolTip("选择支付方式!") #设置提示
self.tb.setText("支付方式")
self.tb.setIcon(QIcon(r'Qt设计师/china.ico'))
self.tb.setAutoRaise(True) #此属性保持是否启用自动升起,默认是禁用的(即False)
# self.tb.setPopupMode(QToolButton.MenuButtonPopup) #按下箭头显示下拉菜单
# self.tb.setPopupMode(QToolButton.DelayedPopup) #一直按箭头 一段时间后显示下拉菜单(默认)
self.tb.setPopupMode(QToolButton.InstantPopup) # 无延时,按下图标即可显示下拉菜单 menu = QMenu()
self.alipayAct = QAction(QIcon('Qt设计师/icon/alipay.ico'),"支付宝")
self.wechatAct = QAction(QIcon('Qt设计师/icon/wechat.ico'),"微信")
self.master_cardAct = QAction(QIcon('Qt设计师/icon/master_card.ico'),"万事达")
self.visaAct = QAction(QIcon('Qt设计师/icon/visa.ico'),"Visa")
menu.addAction(self.alipayAct)
menu.addAction(self.wechatAct)
menu.addAction(self.master_cardAct)
menu.addAction(self.visaAct) self.tb.setMenu(menu) self.alipayAct.triggered.connect(self.on_click)
self.wechatAct.triggered.connect(self.on_click)
self.master_cardAct.triggered.connect(self.on_click)
self.visaAct.triggered.connect(self.on_click) def on_click(self):
if self.sender() == self.alipayAct:
QDesktopServices.openUrl(QUrl("https://www.alipay.com/"))
elif self.sender() == self.wechatAct:
QDesktopServices.openUrl(QUrl("https://pay.weixin.qq.com/index.php"))
elif self.sender() == self.visaAct:
QDesktopServices.openUrl(QUrl("https://www.visa.com.cn/"))
elif self.sender() == self.master_cardAct:
QDesktopServices.openUrl(QUrl("https://www.mastercard.com.cn/zh-cn.html")) if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

QToolButton()+QAction()+QDesktopServices()+QUrl()

补充:用QT设计师完成

from PyQt5.QtWidgets import QMenu,QAction
from PyQt5.QtGui import QIcon,QDesktopServices
from PyQt5.QtCore import QUrl
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(571, 434)
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(12)
Dialog.setFont(font)
Dialog.setSizeGripEnabled(True) self.toolButton = QtWidgets.QToolButton(Dialog)
self.toolButton.setGeometry(QtCore.QRect(120, 100, 121, 81))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("china.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.toolButton.setIcon(icon)
self.toolButton.setIconSize(QtCore.QSize(50, 50))
# self.toolButton.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup) #按下箭头显示下拉菜单
# self.toolButton.setPopupMode(QtWidgets.QToolButton.DelayedPopup) #一直按下箭头一段时间后显示下拉菜单
self.toolButton.setPopupMode(QtWidgets.QToolButton.InstantPopup) #无延时,按下图标即可显示下拉菜单
self.toolButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.toolButton.setAutoRaise(False)
self.toolButton.setArrowType(QtCore.Qt.NoArrow)
self.toolButton.setObjectName("toolButton") menu = QMenu(self)
self.alipayAct = QAction(QIcon('icon/alipay.ico'), '支付宝支付', self)
self.wechatAct = QAction(QIcon('icon/wechat.ico'), '微信支付', self)
self.visaAct = QAction(QIcon('icon/visa.ico'), 'Visa卡支付', self)
self.master_cardAct = QAction(QIcon('icon/master_card.ico'), '万事达卡支付', self) menu.addAction(self.alipayAct)
menu.addAction(self.wechatAct)
menu.addSeparator()
menu.addAction(self.visaAct)
menu.addAction(self.master_cardAct) self.toolButton.setMenu(menu) self.alipayAct.triggered.connect(self.on_click)
self.wechatAct.triggered.connect(self.on_click)
self.visaAct.triggered.connect(self.on_click)
self.master_cardAct.triggered.connect(self.on_click) self.retranslateUi(Dialog)
# QtCore.QMetaObject.connectSlotsByName(Dialog) def on_click(self):
if self.sender() == self.alipayAct:
QDesktopServices.openUrl(QUrl('https://www.alipay.com/'))
elif self.sender() == self.wechatAct:
QDesktopServices.openUrl(QUrl('https://pay.weixin.qq.com/index.php'))
elif self.sender() == self.visaAct:
QDesktopServices.openUrl(QUrl('https://www.visa.com.cn/'))
else:
QDesktopServices.openUrl(QUrl('https://www.mastercard.com.cn/zh-cn.html')) def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.toolButton.setToolTip(_translate("Dialog", "选择你的支付方式"))
self.toolButton.setText(_translate("Dialog", "支付方式"))

界面

# -*- coding: utf-8 -*-
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog, QApplication
from Ui_toolbtn import Ui_Dialog class Dialog(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.setupUi(self) if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
ui = Dialog()
ui.show()
sys.exit(app.exec_())

逻辑

抽象按钮(QAbstractButton)

效果如下:

案例1

【PyQt5-Qt Designer】按钮系列

案例2:

【PyQt5-Qt Designer】按钮系列

案例3:

【PyQt5-Qt Designer】按钮系列

参考:

https://zhuanlan.zhihu.com/p/32818176

完整代码:

from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QMessageBox,QGridLayout,QLabel)
import sys class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,200,300)
self.setWindowTitle("抽象按钮1")
gridLayout = QGridLayout()
self.lb1 = QLabel("密码输入区:")
self.lb2 = QLabel("正确密码:麻")
self.lb3 = QLabel("你输入的密码:")
self.btn1 = QPushButton("芝")
self.btn1.setMinimumSize(40,40)
self.btn2 = QPushButton("麻")
self.btn2.setMinimumSize(40, 40)
self.btn3 = QPushButton("开")
self.btn3.setMinimumSize(40, 40)
self.btn4 = QPushButton("门")
self.btn4.setMinimumSize(40, 40)
gridLayout.addWidget(self.lb1,0,0,1,1)
gridLayout.addWidget(self.lb2,3,0,1,1)
gridLayout.addWidget(self.lb3,4,0,1,1)
gridLayout.addWidget(self.btn1,1,1,1,1)
gridLayout.addWidget(self.btn2,1,2,1,1)
gridLayout.addWidget(self.btn3,2,1,1,1)
gridLayout.addWidget(self.btn4,2,2,1,1)
self.setLayout(gridLayout) self.btn1.setCheckable(True)
self.btn2.setCheckable(True)
self.btn3.setCheckable(True)
self.btn4.setCheckable(True)
self.btn1.setAutoExclusive(True)
self.btn2.setAutoExclusive(True)
self.btn3.setAutoExclusive(True)
self.btn4.setAutoExclusive(True) self.btn1.clicked.connect(self.setPassword)
self.btn2.clicked.connect(self.setPassword)
self.btn3.clicked.connect(self.setPassword)
self.btn4.clicked.connect(self.setPassword) def setPassword(self):
word = self.sender().text()
self.lb3.setText("你输入的密码:"+word)
if word == "麻":
QMessageBox.information(self,"信息提示框","恭喜你,密码输入正确!") if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

抽象按钮-案例1

 from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QMessageBox,QGridLayout,QLabel)
import sys class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,200,300)
self.setWindowTitle("抽象按钮2")
gridLayout = QGridLayout()
self.lb1 = QLabel("密码输入区:")
self.lb2 = QLabel("正确密码:芝麻开门")
self.lb3 = QLabel("你输入的密码:")
self.btn1 = QPushButton("芝")
self.btn1.setMinimumSize(40,40)
self.btn2 = QPushButton("麻")
self.btn2.setMinimumSize(40, 40)
self.btn3 = QPushButton("开")
self.btn3.setMinimumSize(40, 40)
self.btn4 = QPushButton("门")
self.btn4.setMinimumSize(40, 40)
gridLayout.addWidget(self.lb1,0,0,1,1)
gridLayout.addWidget(self.lb2,3,0,1,1)
gridLayout.addWidget(self.lb3,4,0,1,1)
gridLayout.addWidget(self.btn1,1,1,1,1)
gridLayout.addWidget(self.btn2,1,2,1,1)
gridLayout.addWidget(self.btn3,2,1,1,1)
gridLayout.addWidget(self.btn4,2,2,1,1)
self.setLayout(gridLayout) self.btn1.setCheckable(True)
self.btn2.setCheckable(True)
self.btn3.setCheckable(True)
self.btn4.setCheckable(True)
self.btn1.setAutoExclusive(True)
self.btn2.setAutoExclusive(True)
self.btn3.setAutoExclusive(True)
self.btn4.setAutoExclusive(True)
self.password = "" self.btn1.clicked.connect(self.setPassword)
self.btn2.clicked.connect(self.setPassword)
self.btn3.clicked.connect(self.setPassword)
self.btn4.clicked.connect(self.setPassword) def setPassword(self,pressed):
word = self.sender().text()
if pressed:
if len(self.password) < 4:
self.password += word
else:
self.password = self.password.replace(word, '') self.lb3.setText("你输入的密码:"+self.password)
if len(self.password) == 4 and self.password == '芝麻开门':
QMessageBox.information(self, '提示', '恭喜,密码正确,可以进入!') if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

抽象按钮-案例2

 from PyQt5.QtWidgets import (QApplication,QWidget,QPushButton,QMessageBox,QGridLayout,QLabel,QButtonGroup)
import sys class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI() def initUI(self):
self.setGeometry(300,300,200,300)
self.setWindowTitle("抽象按钮3")
gridLayout = QGridLayout()
self.lb1 = QLabel("密码输入区:")
self.lb2 = QLabel("正确密码:321")
self.lb3 = QLabel("你输入的密码:")
self.btn11 = QPushButton("")
self.btn11.setMinimumSize(40,40)
self.btn12 = QPushButton("")
self.btn12.setMinimumSize(40, 40)
self.btn13 = QPushButton("")
self.btn13.setMinimumSize(40, 40)
self.btn21 = QPushButton("")
self.btn21.setMinimumSize(40, 40)
self.btn22 = QPushButton("")
self.btn22.setMinimumSize(40, 40)
self.btn23 = QPushButton("")
self.btn23.setMinimumSize(40, 40)
self.btn31 = QPushButton("")
self.btn31.setMinimumSize(40, 40)
self.btn32 = QPushButton("")
self.btn32.setMinimumSize(40, 40)
self.btn33 = QPushButton("")
self.btn33.setMinimumSize(40, 40)
gridLayout.addWidget(self.lb1,0,0,1,1)
gridLayout.addWidget(self.lb2,4,0,1,1)
gridLayout.addWidget(self.lb3,5,0,1,1)
gridLayout.addWidget(self.btn11,1,1,1,1)
gridLayout.addWidget(self.btn12,1,2,1,1)
gridLayout.addWidget(self.btn13,1,3,1,1)
gridLayout.addWidget(self.btn21,2,1,1,1)
gridLayout.addWidget(self.btn22,2,2,1,1)
gridLayout.addWidget(self.btn23,2,3,1,1)
gridLayout.addWidget(self.btn31,3,1,1,1)
gridLayout.addWidget(self.btn32,3,2,1,1)
gridLayout.addWidget(self.btn33,3,3,1,1)
self.setLayout(gridLayout) self.btn11.setCheckable(True)
self.btn12.setCheckable(True)
self.btn13.setCheckable(True)
self.btn21.setCheckable(True)
self.btn22.setCheckable(True)
self.btn23.setCheckable(True)
self.btn31.setCheckable(True)
self.btn32.setCheckable(True)
self.btn33.setCheckable(True) self.btg1 = QButtonGroup(self)
self.btg2 = QButtonGroup(self)
self.btg3 = QButtonGroup(self) self.btg1.addButton(self.btn11,1)
self.btg1.addButton(self.btn12,2)
self.btg1.addButton(self.btn13,3)
self.btg2.addButton(self.btn21,1)
self.btg2.addButton(self.btn22,2)
self.btg2.addButton(self.btn23,3)
self.btg3.addButton(self.btn31,1)
self.btg3.addButton(self.btn32,2)
self.btg3.addButton(self.btn33,3) self.pwd1 , self.pwd2 ,self.pwd3 = "","","" self.btg1.buttonClicked.connect(self.setPassWord)
self.btg2.buttonClicked.connect(self.setPassWord)
self.btg3.buttonClicked.connect(self.setPassWord) def setPassWord(self):
sender = self.sender()
if sender == self.btg1:
self.pwd1 = str(self.btg1.checkedId())
elif sender == self.btg2:
self.pwd2 = str(self.btg2.checkedId())
elif sender == self.btg3:
self.pwd3 = str(self.btg3.checkedId()) you_password = self.pwd1+self.pwd2+self.pwd3
self.lb3.setText(you_password)
if you_password == "":
QMessageBox.information(self,"提示框","恭喜你密码正确!",QMessageBox.Ok|QMessageBox.Cancel|QMessageBox.Close,QMessageBox.Ok)
elif len(you_password) == 3 and you_password != "":
QMessageBox.warning(self,"警告框","密码输入错误,请重新输入!") if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())

抽象按钮-案例3

【PyQt5-Qt Designer】按钮系列的更多相关文章

  1. PyQt5 &amp&semi; Qt Designer使用小结

    开始在知乎写文章的原因,主要还是想整理平时的经验,方便自己以后查看,有机会的话大家也可以交流吧. 11月中旬由于项目需要,和另一名实习生负责使用Python开发一个数据分析的小软件. 虽然才开始接触Q ...

  2. PyCharm&plus;PyQt5&plus;Qt Designer配置

    配置前提 因为本机已经配置完毕了,本次使用的是虚拟机中的Win7系统,Win10系统操作步骤完全一样,无任何区别 PyCharm (这个不多说,官网下载安装,我是用的是2019.3版本) Python ...

  3. 痞子衡嵌入式:超级好用的可视化PyQt GUI构建工具&lpar;Qt Designer&rpar;

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是PyQt GUI构建工具Qt Designer. 痞子衡开博客至今已有好几年,一直以嵌入式开发相关主题的文章为主线,偶尔穿插一些其他技术 ...

  4. PyCharm&plus;Qt Designer&plus;PyUIC安装配置教程

    Qt Designer用于像VC++的MFC一样拖放.设计控件 PyUIC用于将Qt Designer生成的.ui文件转换成.py文件 Qt Designer和PyUIC都包含在PyQt5中,所以我们 ...

  5. pyqt5 在qt designer后以弹窗的方式连接多个UI图形界面

    当我们通过pyqt开发时,eric6为我们提供了一个方便的工具:图形化的绘制UI工具--qt designer. 我们可以通过它开发多个UI,然后利用信号-槽工具,将功能代码附着在上面.也可以将多个界 ...

  6. Win10安装PyQt5与Qt Designer【转】

    https://blog.csdn.net/u011342224/article/details/78879633 1.直接在cmd中通过pip安装PyQt5 1 pip install pyqt5 ...

  7. Win10安装PyQt5与Qt Designer

    1.直接在cmd中通过pip安装PyQt5 1 pip install pyqt5 会自动下载PyQt5以及sip并安装,因为PyQt5不再提供Qt Designer等工具,所以需要再安装pyqt5- ...

  8. pyqt5对用qt designer设计的窗体实现弹出子窗口的示例

    pyqt5对用qt designer设计的窗体实现弹出子窗口的示例 脚本专栏 python 1. 用qt designer编写主窗体,窗体类型是MainWindow,空白窗口上一个按钮.并转换成mai ...

  9. 使用 PySide2 开发 Maya 插件系列一:QT Designer 设计GUI, pyside-uic 把 &period;ui 文件转为 &period;py 文件

    使用 PySide2 开发 Maya 插件系列一:QT Designer 设计GUI, pyside-uic 把 .ui 文件转为 .py 文件 前期准备: 安装 python:https://www ...

随机推荐

  1. Java集合——Map接口

    1.定义 Map用于保存存在映射关系<key,value>的数据.其中,key值不能重复(使用equals()方法比较),value值可以重复 2.方法 V  put(key,value) ...

  2. allegro蛇形线

    蛇形线设置: 设置之后,框选你要修改的线即可: 修线: --------------------------------

  3. 在html页面中展示JSON

    背景: 有时候我们需要将json数据直接显示在页面上(比如在做一个接口测试的项目,需要将接口返回的结果直接展示),但是如果直接显示字符串,不方便查看.需要格式化一下. 解决方案: 其实JSON.str ...

  4. &lbrack;记录&rsqb;一则清理MySQL大表以释放磁盘空间的案例

    一则清理MySQL大表以释放磁盘空间的案例 一.基本情况: 1.dbtest库554G,先清理st_online_time_away_ds(37G)表的数据,保留半年的数据: 1)删除的数据:sele ...

  5. iOS 滚动视图的复用问题解决方案

    LazyScroll是什么 LazyScrollView 继承自ScrollView,目标是解决异构(与TableView的同构对比)滚动视图的复用回收问题.它可以支持跨View层的复用,用易用方式来 ...

  6. embed 引入网上视频

    <p>embed引入网上视频</p> <embed src='http://player.youku.com/player.php/sid/XMjgxODkyMTIxNg ...

  7. Intellij IDEA 通过数据库表逆向生成带注释的实体类文件超级详细步骤,附详细解决方案

    参考:https://blog.csdn.net/qq_34371461/article/details/80571281  https://blog.csdn.net/mqchenrong/arti ...

  8. 移动前端开发之viewport的深入理解 --- 待续

    在移动设备上进行网页的重构或开发, 只有明白了viewport的概念 才能 响应 各种  不同分辨率 的移动设备 一.viewport的概念 通俗的讲,移动设备上的viewport就是设备的屏幕上能用 ...

  9. 高级类特性----接口&lpar;intertface&rpar;

    接 口 有时必须从几个类中派生出一个子类,继承它们所有的属性和方法.但是,Java不支持多重继承.有了接口,就可以得到多重继承的效果. 接口(interface)是抽象方法和常量值的定义的集合. 从本 ...

  10. Spring quantz--定时任务调度工具

    1.在xml中交给spring管理的一些类 <bean id="cancelOrderJobDetail" class="org.springframework.s ...