import sys from PyQt5.QtWidgets import * class SignalSlotDemo(QWidget): """ 信号(Signal)与槽(Slot) 信号本质上来讲是一个事件,需要程序或者点击等事件来触发 槽一般是指函数或者方法,槽是接收信号的程序 """ def __init__(self): super(SignalSlotDemo, self).__init__() self.initUI() def initUI(self): self.setWindowTitle('信号(Signal)与槽(Slot)') self.resize(300, 200) self.btn = QPushButton('我的按钮', self) # 没有布局的话,就直接添加到窗口上 self.btn.clicked.connect(self.onClick) def onClick(self): self.btn.setText('信号已经发出') # 设置样式,定制外观 self.setStyleSheet('QPushButton{max-width:200px;min-width:200px;background:yellow;color:red}') # 这里要用大括号 if __name__ == '__main__': app = QApplication(sys.argv) main = SignalSlotDemo() print(main.__doc__) main.show() sys.exit(app.exec_())结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)