python Qlabel不显示图像

时间:2015-08-07 10:54:41

标签: python pyqt

我试图在每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()`

1 个答案:

答案 0 :(得分:0)

如果我走线

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
相关问题