【发布时间】:2015-09-05 10:26:32
【问题描述】:
import functools
from code.ghosts import Ghosts
class Pacman(QtGui.QGraphicsPixmapItem):
def __init__(self):
super(Pacman, self).__init__()
self.setPixmap(QtGui.QPixmap("pacman.png"))
def game_continue(self):
objects = list(self.scene().items())
for i in range(objects.__len__()):
if type(objects[i]) is Ghosts:
self.scene().removeItem(objects[i])
func = functools.partial(self.show_again, objects)
QtCore.QTimer.singleShot(100, func)
def show_again(self, objects):
for object_ in objects:
if type(object_) is Ghosts:
self.scene().addItem(object_)
它告诉我 NoneType 对象没有属性 addItem (它是关于代码最后一行的 self.scene() )。怎么会识别self.scene.removeItem()并执行却没有addItem?
【问题讨论】:
-
您是否已将
Pacman实例添加到场景中?如果没有,self.scene()将返回None -
我已经添加了它,但是在阅读了下面的评论后,我明白了我的错误。谢谢你的回答:)
标签: pyqt add selecteditem scene