Actually, the new button is created. It just didn't show. By adding the line -- self.pushButton.show() -- it now shows. Here's the revised code that works.
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(400, 300) def setup_pushButton(self, word, x, y, width, height): self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(x, y, width, height)) self.pushButton.setText(word) self.pushButton.clicked.connect(self.but_clicked) def create_pushButtons(self): self.setup_pushButton('apple', 100, 110, 75, 23) self.setup_pushButton('car', 20, 110, 75, 23) def but_clicked(self): print('clicked') self.setup_pushButton('house', 250, 110, 75, 23) self.pushButton.show() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) ui.create_pushButtons() Form.show() sys.exit(app.exec_()) [/python [hr] Actually, the new button is created. It just didn't show. By adding the line -- self.pushButton.show() -- it now shows. Here's the revised code that works. [python] from PyQt5 import QtCore, QtGui, QtWidgets class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(400, 300) def setup_pushButton(self, word, x, y, width, height): self.pushButton = QtWidgets.QPushButton(Form) self.pushButton.setGeometry(QtCore.QRect(x, y, width, height)) self.pushButton.setText(word) self.pushButton.clicked.connect(self.but_clicked) def create_pushButtons(self): self.setup_pushButton('apple', 100, 110, 75, 23) self.setup_pushButton('car', 20, 110, 75, 23) def but_clicked(self): print('clicked') self.setup_pushButton('house', 250, 110, 75, 23) self.pushButton.show() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) Form = QtWidgets.QWidget() ui = Ui_Form() ui.setupUi(Form) ui.create_pushButtons() Form.show() sys.exit(app.exec_())