title: Pyqt5 method to close or delete the widget and setup it again on command
body: <p>I have created short application with Pyqt5 designer:</p>
  
  <p>Here is the code:</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  
  class Ui_Form(object):
      def setupUi(self, Form):
          Form.setObjectName("Form")
          Form.resize(752, 674)
          self.formLayout_2 = QtWidgets.QFormLayout(Form)
          self.formLayout_2.setObjectName("formLayout_2")
          self.formLayout = QtWidgets.QFormLayout()
          self.formLayout.setObjectName("formLayout")
          self.formLayout_2.setLayout(0, QtWidgets.QFormLayout.LabelRole, self.formLayout)
          self.pushButton = QtWidgets.QPushButton(Form)
          self.pushButton.setObjectName("pushButton")
          self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.pushButton)
          self.widget = QtWidgets.QWidget(Form)
          sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
          sizePolicy.setHorizontalStretch(0)
          sizePolicy.setVerticalStretch(1)
          sizePolicy.setHeightForWidth(self.widget.sizePolicy().hasHeightForWidth())
          self.widget.setSizePolicy(sizePolicy)
          self.widget.setStyleSheet("background-color:white;")
          self.widget.setObjectName("widget")
          self.formLayout_2.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.widget)
          self.pushButton_2 = QtWidgets.QPushButton(Form)
          self.pushButton_2.setObjectName("pushButton_2")
          self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.pushButton_2)
  
          self.retranslateUi(Form)
          QtCore.QMetaObject.connectSlotsByName(Form)
  
      def retranslateUi(self, Form):
          _translate = QtCore.QCoreApplication.translate
          Form.setWindowTitle(_translate("Form", "Form"))
          self.pushButton.setText(_translate("Form", "Letters"))
          self.pushButton_2.setText(_translate("Form", "Numbers"))
  
  
  if __name__ == "__main__":
      import sys
      app = QtWidgets.QApplication(sys.argv)
      Form = QtWidgets.QWidget()
      ui = Ui_Form()
      ui.setupUi(Form)
      Form.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>This script is connected to appexe script(dialog):</p>
  
  <pre><code>import sys
  from PyQt5 import QtWidgets, QtCore, QtGui
  import string
  from functools import partial
  from setup_test import Ui_Form
  from PyQt5.QtWidgets import QWidget, QGridLayout, QPushButton, QApplication
  
  
  
  class myprog(Ui_Form):
      def __init__ (self, dialog):
          Ui_Form.__init__(self)
          self.setupUi(dialog)
  
  
          self.symbols = [string.ascii_lowercase, string.digits]
          self.buttons = [self.pushButton, self.pushButton_2]
  
          for i,v in enumerate(self.buttons):
              self.buttons[i].clicked.connect(partial(self.application, i))
  
      def application(self, i):
  
          self.grid1 = QGridLayout(self.widget)
          names = [x for x in self.symbols[i]]
          positions = [(j,d) for j in range(7) for d in range(6)]
  
          for a,b in zip(positions, names):
              button = QPushButton(b)
  
              self.grid1.addWidget(button, *a) 
  
          print(self.grid1.count())
  
  
  
  
  
  
  if __name__ == '__main__':
      app = QtWidgets.QApplication(sys.argv)
      dialog = QtWidgets.QDialog()
  
      appexe = myprog(dialog)
      dialog.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>I am new to Pyqt5. The basic idea is: whenever you click the button 'Letters' or button 'Numbers', the widget below should layout all the sysmbols within Letters or buttons. </p>
  
  <p>If you do execute the appexe script, you can see, it works for the first try. (Please ignore the visual design). I am happy with the result. When button is pressed, it shows the buttons in grid(widget).</p>
  
  <p>The problem I am facing is, how to clear the grid and it's widget when other button is hit > and display the new grid, new widgets.</p>
  
  <p>If you look close, there is also a print statement:</p>
  
  <pre><code>print(self.grid1.count())
  </code></pre>
  
  <p>When I am in application and i am clicking letter and number button, it tells me how many widgets are within grid, however I just can't find a way how to display the new setup.</p>
  
  <p>I would appreciate your help and your ideas. Thank you.</p>