classDemo(QWidget):def__init__(self):super(Demo,self).__init__()
self.label = QLabel('label')
self.btn = QPushButton('button')## 连接函数 这里有两个信号
self.btn.pressed.connect(self.ChangeText)
self.btn.released.connect(self.ChangeText)
self.v_layout = QVBoxLayout()
self.v_layout.addWidget(self.label)
self.v_layout.addWidget(self.btn)
self.setLayout(self.v_layout)
self.count =0# 定义槽函数 一个槽函数defChangeText(self):
self.count = self.count +1if self.count %2==1:# pressed
self.label.setText('haha, i have pressed this button')else:# released
self.label.setText('xixi, i have released this button')print('I have clicked this button for :', self.count/2)