小编vix*_*enn的帖子

PyQt4 - 创建一个计时器

我很抱歉这个问题,但我已经阅读了很多东西,似乎我没有得到如何制作计时器.所以我发布了我的代码:

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())
Run Code Online (Sandbox Code Playgroud)

我试图让物体每200ms朝着它的目标前进.我试过没有自己它给了我同样的错误:

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' …
Run Code Online (Sandbox Code Playgroud)

python timer pyqt

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

pyqt ×1

python ×1

timer ×1