0

Pretty new to the Python GUI. I'm creating a small program, in which i have a button and when i press it, it should create another button in the GUI.

Tried this :

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot

class App(QMainWindow):

    def __init__(self):
        super().__init__()
        self.title = 'PyQt5 Pet Project'
        self.left = 10
        self.top = 10
        self.width = 1000
        self.height = 700
        self.initUI()

    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(self.left,  self.top,  self.width,  self.height)

        # Create a button in the window
        self.buttonA = QPushButton('Simple If',  self)
        self.buttonA.move(10, 10)
        # connect button to function on_click
        self.buttonA.clicked.connect(self.on_click)
        self.show()

    def on_click(self):
        # Need to create a button here , only if buttonA is pressed
        self.buttonB = QPushButton('Simple If',  self)
        self.buttonB.move(200, 10)
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

But its not updating anything in the GUI. Searched for the GUI update as well but nothing worked for me.

Preetham
  • 577
  • 5
  • 13

0 Answers0