pyqt之qpushbutton

常用方法如下

pyqt之qpushbutton_第1张图片

测试代码如下

import sys

from PyQt5.QtWidgets import QWidget,QApplication,QPushButton


class MyClass(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('编程')
        self.resize(800,600)
        self.qpush1=QPushButton(self)
        self.qpush1.setText('我是第一个按钮')
        self.qpush1.clicked[bool].connect(self.firstfunction)

        self.qpush2=QPushButton(self)
        self.qpush2.setText('我是第二个按钮')
        self.qpush2.move(0,50)
        self.qpush2.clicked.connect(self.secondfunction)

        self.qpush3=QPushButton(self)
        self.qpush3.setText("我是第三个按钮")
        self.qpush3.move(0, 100)
        self.qpush3.toggled.connect(self.thirdfunction)
        self.qpush3.setCheckable(True)

        self.show()

    def firstfunction(self,status):
       
        print('this is first')
        print(status)
    def secondfunction(self):
        print('this is second')
    def thirdfunction(self,status):
        print('this is third')
        print(status)
if __name__ == '__main__':
    app=QApplication(sys.argv)
    mc=MyClass()

    app.exec()

你可能感兴趣的:(pyqt之qpushbutton)