我很抱歉问这个问题,但我读了很多东西,似乎我不知道怎么做计时器。所以我要发布我的代码:
from PyQt4 import QtGui, QtCore
from code.pair import Pair
from code.breadth_first_search import breadth_first_search
import functools
class Ghosts(QtGui.QGraphicsPixmapItem):
def __init__(self, name):
super(Ghosts, self).__init__()
self.set_image(name)
def chase(self, goal):
pos = Pair(self.x(), self.y())
path = breadth_first_search(pos, goal)
while not path.empty():
aim = path.get_nowait()
func = functools.partial(self.move_towards, aim)
timer = QtCore.QTimer()
QtCore.QTimer.connect(timer, QtCore.SIGNAL("timeout()"), self, QtCore.SLOT("func()"))
timer.start(200)
def move_towards(self, goal):
self.setPos(goal.first(), goal.second())
我正试图使物体每200米向目标移动。 我试过没有自我它给我同样的错误:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'bytes'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type 'bytes'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 2 has unexpected type 'bytes'
我不知道如何将计时器连接到带有参数的函数。 我以为我没有正确地使用SLOT参数,但它给了我这些自知之明。我想这都是错的。我很感激你的帮助:)
使用新型信号,它们更容易理解。
交换-
与-
一个简单但完整的计时器示例-
相关问题 更多 >
编程相关推荐