I'm trying to create a window(UI) that have a button click action implemented using python and PyQt5. But, i want my button to create a new button when i clicked it. (i.e: clicking a button to create a new button). Can some one notify me on how to do that? my sample code is as follows:
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
import sys
class App(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("my window")
self.setGeometry(100, 100, 320, 200)
#creating a button to be clicked
button1 = QPushButton('Button-1', self)
button1.move(100, 70)
#calling a function on_click upon clicking button1, i want this function to create a new button named button2
button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
print('Button-2 will be created')
button2 = QPushButton('Button-2', self)
button2.move(100, 200)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
I want my function, the on_click(self), to create a new button: but i can't. do i miss something?