title: Remove Widget and Layout in PyQt
body: <p>Whenever i clicked on Size Button it only clear TEXT field.</p>
  
  <p>i want to clear all layout as well as Widgets!</p>
  
  <p>i am new in python programming.
  Can you help me for solve problem.</p>
  
  <pre><code>import sys
  from PyQt4 import QtGui, QtCore
  
  class Example(QtGui.QWidget):
  
  def __init__(self):
      super(Example, self).__init__()
  
      self.homeScreenBox = QtGui.QGridLayout()
      self.editTextScreenBox = QtGui.QVBoxLayout()
  
  
      vbox = QtGui.QGridLayout()
      vbox.addLayout(self.homeScreenBox,0,0)
      vbox.addLayout(self.editTextScreenBox,0,0)
  
      self.setLayout(vbox)
  
      self.homeScreen()
      self.showFullScreen()
      self.show()
  
  def editTextScreen(self):
  
      self.mybox = QtGui.QHBoxLayout()
      self.mybox2 = QtGui.QHBoxLayout()
      self.editTextScreenBox.addLayout(self.mybox)
      self.editTextScreenBox.addLayout(self.mybox2)
  
      self.btnbtn = QtGui.QPushButton("LOL")
      self.mybox.addWidget(self.btnbtn)
      self.lolmlol = QtGui.QPushButton("lomlol")
      self.mybox2.addWidget(self.lolmlol)
      self.uloo = QtGui.QPushButton("looloolool")
      self.mybox.addWidget(self.uloo)
  
  
  
  
  def keyPressEvent(self, event):
      if event.key() == QtCore.Qt.Key_Escape:
          self.close()
  
  def homeScreen(self):
      self.home_box_up = QtGui.QVBoxLayout()
      self.home_box_down = QtGui.QVBoxLayout()
  
      self.homeScreenBox.addLayout(self.home_box_up,0,0)
      self.homeScreenBox.addLayout(self.home_box_down,1,0)
  
      self.h1 = QtGui.QHBoxLayout()
      self.h2 = QtGui.QHBoxLayout()
      self.h3 = QtGui.QHBoxLayout()
  
      self.home_box_down.addLayout(self.h1)
      self.home_box_down.addLayout(self.h2)
      self.home_box_down.addLayout(self.h3)
  
      self.txt_home = QtGui.QLabel("TEXT")
      self.home_box_up.addWidget(self.txt_home)
  
      self.btnSizeH = QtGui.QPushButton("Size")
      self.btnEditTextH = QtGui.QPushButton("Edit Text")
      self.btnDateH = QtGui.QPushButton("Set Date")
      self.btn4 = QtGui.QPushButton("Button 4")
      self.btn5 = QtGui.QPushButton("Button 5")
      self.btn6 = QtGui.QPushButton("Button 6")
      self.btn7 = QtGui.QPushButton("Button 7")
      self.btn8 = QtGui.QPushButton("Button 8")
      self.btn9 = QtGui.QPushButton("Button 9")
      self.h1.addWidget(self.btnSizeH)
      self.h1.addWidget(self.btnEditTextH)
      self.h1.addWidget(self.btnDateH)
      self.h2.addWidget(self.btn4)
      self.h2.addWidget(self.btn5)
      self.h2.addWidget(self.btn6)
      self.h2.addWidget(self.btn7)
      self.h3.addWidget(self.btn8)
      self.h3.addWidget(self.btn9)
  
      self.txt_home.setStyleSheet("font-size:24px;")        
  
      self.setStyleSheet("QPushButton{font-size:24px;padding:20px;background-color:transparent;\
                              border:2px solid #5585ff;border-radius:35%;box-shadow: 10px 10px;\
                              margin:10px}"
                         "QPushButton:pressed { background-color:grey }")
  
      self.connect(self.btnSizeH, QtCore.SIGNAL("clicked()"), self.home_edit)
  
  def home_edit(self):
      self.remove_homeScreen(self.homeScreenBox)
      #self.editTextScreen()
  
  
  def remove_homeScreen(self, layout):
      #for cnt in reversed(range(self.homeScreenBox.count())):
      #    widget = self.homeScreenBox.takeAt(cnt).layout()
  
  
      #    if widget is not None:
      #        widget.deleteLater()
  
      for i in reversed(range(layout.count())):
          item = layout.itemAt(i)
  
      if isinstance(item, QtGui.QWidgetItem):
          print "widget" + str(item)
          item.widget().close()
          # or
          # item.widget().setParent(None)
      elif isinstance(item, QtGui.QSpacerItem):
          print "spacer " + str(item)
          # no need to do extra stuff
      else:
          print "layout " + str(item)
          self.remove_homeScreen(item.layout())
  
      # remove the item from layout
      layout.removeItem(item)   
  
  
  
  
  def main():    
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>and if anyone have have another solution, please suggest code for multiple wizard layout application.</p>