Search code examples
pythonpyqtpyqt4qpushbutton

How to delete a button using PYQT4?


I am trying to delete this button

btn = QtGui.QPushButton("Log in", self)
btn.clicked.connect(self.remove)

When the button is clicked, it should disappear,but this doesn't work

btn.deleteQPushButton()

Or if there's any way to entirely delete every button in the window?


Solution

  • An elegant solution is to use deleteLater():

    btn = QtGui.QPushButton("Log in", self)
    btn.clicked.connect(btn.deleteLater)