【发布时间】:2016-06-20 08:42:01
【问题描述】:
假设我想创建一个对话框,我的主程序的子程序:
from PyQt4 import QtGui, QtCore
class WizardJournal(QtGui.QDialog):
def __init__(self, parent):
super(WizardJournal, self).__init__(parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.wizard = QtGui.QWidget()
self.ok_button = QtGui.QPushButton("OK", self)
self.vbox_global = QtGui.QVBoxLayout(self)
self.vbox_global.addWidget(self.ok_button)
self.paret.wizard.setLayout(self.vbox_global)
self.parent.wizard.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
parent = QtGui.QWidget()
obj = WizardJournal(parent)
sys.exit(app.exec_())
这个对话框将由我的主程序打开和关闭。关于内存消耗有什么更好的:
self.ok_button = QtGui.QPushButton("OK", self)self.ok_button = QtGui.QPushButton("OK")
基本上,我想知道在创建小部件时是否应该提及父小部件。当我关闭这个对话框时,如果我在创建它时没有提及父窗口小部件,确定按钮是否会从内存中释放?
【问题讨论】: