pythonqlabel不显示图像

2024-09-19 23:34:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着每5秒钟动态更改一次图像,第一次显示正确,之后什么都不显示,这是我的代码

 def imageSelect(self):

    name = self.selectImageFromDb()#Fetch image name from database one by one

    self.pic.clear()
    myPixmap = QtGui.QPixmap(_fromUtf8(path + "images/" + name))

    self.pic.setPixmap(myPixmap)

    self.pic.show()

    threading.Timer(3, self.imageSelect).start()`

Tags: 代码namefrom图像imageselfdef动态
1条回答
网友
1楼 · 发布于 2024-09-19 23:34:16

如果我接电话

threading.Timer(3, self.imageSelect).start()

在函数imageSelect()之外,我可以重现这种行为。我收到错误消息:

QObject::startTimer: Timers can only be used with threads started with QThread

所以我改用QTimer(成功):

self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.imageSelect)
self.timer.start(1000)            # interval in milliseconds

相关问题 更多 >