我试图对setParentPython中的一个对象(一个继承自不同类的类的实例 - 具体而言QtGui.QLabel)执行一些操作(),但是在运行时期间引发了上述错误.对象本身有一些具有实际内容的字段(在调试时验证),但由于某种原因我无法"使用"它.错误意味着什么,我该如何解决?对于一些其他信息,我会说在我尝试对它执行此操作之前,该对象是从静态方法返回的.
子类具有__init__()自己的功能:
def __init__(self, image, father):
super(AtomicFactory.Image, self).__init__(father)
self.raw_attributes = image.attributes
self.attributes = {}
father.addChild(self)
self.update()
Run Code Online (Sandbox Code Playgroud)
现在我写了一个类似的代码,一个简单的代码,widget.setParent(mw)当窗口移动时在行上有相同的错误.
#!/usr/bin/env python
import sys
import copy
from PyQt4 import QtCore, QtGui
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main_widget=QtGui.QWidget()
widget = QtGui.QPushButton('Test')
widget.resize(640, 480)
widget.setParent(main_widget)
widget.move(0, 0)
widget2=QtGui.QPushButton('Test2')
widget2.i=0
widget2.resize(600, 200)
widget2.setParent(main_widget)
widget2.move(640, 0)
def onResize(event):
print event
mw=copy.deepcopy(main_widget)
widget.setParent(mw)
widget2.setParent(mw)
widget.move(0, 0)
widget2.move(640, 480)
main_widget_width=main_widget.width()
widget_width=widget.width()
width2=main_widget_width-widget_width
height2=widget2.height()
widget2.resize(width2, height2)
widget2.move(640, 0) …Run Code Online (Sandbox Code Playgroud)