首页 > 其他分享> > PyQt5基础学习-QPushButton().clicked.connect(信号和槽) 1.QPushButton().setStyleSheet("设置风格的执行函数")
PyQt5基础学习-QPushButton().clicked.connect(信号和槽) 1.QPushButton().setStyleSheet("设置风格的执行函数")
作者:互联网
通过对按钮绑定函数来生成信号和槽,即信号是按钮点击时发送的信号, 槽为对应绑定的函数
SignalSlotDemo.py
""" 信号(Signal) 与槽(Slot) """ from PyQt5.QtWidgets import * import sys class SigalSlotDemo(QWidget): def __init__(self): super(SigalSlotDemo, self).__init__() self.initUI() def onClick(self): self.btn.setText("信号已经发出") self.btn.setStyleSheet("QPushButton(max-width:200px;min-width:200px)") def initUI(self): self.setGeometry(300, 300, 500, 400) self.setWindowTitle("信号(Signal)与槽(Slot)") self.btn = QPushButton("我的按钮", self) self.btn.clicked.connect(self.onClick) if __name__ == "__main__": app = QApplication(sys.argv) main = SigalSlotDemo() main.show() sys.exit(app.exec_())
标签:__,main,clicked,信号,self,PyQt5,QPushButton,btn 来源: https://www.cnblogs.com/hyq-lst/p/15866324.html