title: How to delete widgets
body: <p>The posted code creates a single window with 5 rows of widgets.
  Clicking <code>Push Button</code> fires up <code>btnClicked</code> function which fails to clear the window from all the widgets using <code>.takeAt()</code> method. Why?</p>
  
  <p><a href="https://i.stack.imgur.com/2wdnz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2wdnz.png" alt="enter image description here"></a></p>
  
  <pre><code>from PyQt4 import QtCore, QtGui
  app = QtGui.QApplication([])
  
  view = QtGui.QWidget() 
  view.setLayout(QtGui.QVBoxLayout())
  
  def btnClicked():
      items = []
      for i in range( view.layout().count() ):
          item = view.layout().itemAt(i)
          items.append(item)
  
      for num, item in enumerate(items):
          print 'taking out item:', num, item 
          view.layout().takeAt(num)
  
  
  for i in range(5):
      sublayout = QtGui.QHBoxLayout()
      view.layout().addLayout(sublayout)
  
      sublayout.addWidget(QtGui.QLabel('Label:'))
      sublayout.addWidget(QtGui.QLineEdit('Text Edit'))
  
      btn = QtGui.QPushButton('Push Button')
      btn.clicked.connect(btnClicked)
      sublayout.addWidget(btn)
  
  view.show()
  app.exec_()
  </code></pre>