If your widget have no child widgets that depend on it i think you can use:
layout.removeWidget(self.widget_name)
self.widget_name.deleteLater()
self.widget_name = None
in my tests when it is a widget that have childs you have to:
import sip
layout.removeWidget(self.widget_name)
sip.delete(self.widget_name)
self.widget_name = None
if you don't have a variable name for the widget at class or global level you still can remove from layout with layout.takeAt(index) and get the widget pointer from the QLayoutItem this functions returns with QLayoutItem.widget() method, in that case you don't need to assign to None the variable name because it is not referenced outside your function.
Try both methods and see what works for you (don't leak memory after repeat a good bunch of times).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…