标签:get def div move sed eve geometry __init__ elf
sender()的方法:
objectName(),获取objectName
text(),获取text
1 import sys 2 from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication 3 4 class Exp(QMainWindow): 5 def __init__(self): 6 super().__init__() 7 self.initUI() 8 9 def initUI(self): 10 btn1 = QPushButton(‘按钮1‘,self) 11 btn1.setObjectName("button1") 12 btn1.move(30,50) 13 14 btn2 = QPushButton(‘按钮2‘,self) 15 btn2.setObjectName("button2") 16 btn2.move(150,50) 17 18 btn1.clicked.connect(self.buttonClicked) 19 btn2.clicked.connect(self.buttonClicked) 20 21 self.statusBar() 22 23 self.setGeometry(300,300,290,150) 24 self.setWindowFilePath(‘Event sender‘) 25 self.show() 26 27 28 def buttonClicked(self): 29 sender = self.sender() 30 self.statusBar().showMessage(sender.text()+‘ ‘+sender.objectName()+ ‘被点击了‘) 31 32 33 if __name__ == ‘__main__‘: 34 app = QApplication(sys.argv) 35 ex = Exp() 36 sys.exit(app.exec_())
标签:get def div move sed eve geometry __init__ elf
原文地址:https://www.cnblogs.com/rita-jia/p/12303078.html