import sysfrom PyQt5.QtWidgets import QApplication, QMainWindow, QPushButtonapp = QApplication(sys.argv)MainWindow = QMainWindow()MainWindow.resize(300,300)btn = QPushButton('test',MainWindow)btn.setObjectName('Button1')def ButtonsOnclick(): global MainWindow print('Click') print(MainWindow.sender().objectName())btn.clicked.connect(ButtonsOnclick)MainWindow.show()sys.exit(app.exec_())