在ubuntu上用pyqt做图片的循环显示,程序如下:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time
class Window(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.thread = Worker()
print "iiiiiiiii"
self.startButton = QPushButton(self.tr("&Start"))
self.viewer = QLabel()
self.viewer.setFixedSize(300, 300)
self.connect(self.thread, SIGNAL("finished()"), self.updateUi)
self.connect(self.thread, SIGNAL("terminated()"), self.updateUi)
self.connect(self.thread, SIGNAL("output(QRect,QPixmap)"), self.addImage)
print "eeeeeeeeee"
self.connect(self.startButton, SIGNAL("clicked()"), self.makePicture)
print "fffffff"
layout = QGridLayout()
layout.addWidget(self.startButton, 0, 2)
layout.addWidget(self.viewer, 1, 0, 1, 3)
self.setLayout(layout)
self.setWindowTitle(self.tr("Simple Threading Example"))
def makePicture(self):
print "mmmmmmmmmm"
self.startButton.setEnabled(True)
print "pppppppp"
#pixmap = QPixmap('1.jpg')
#self.viewer.setPixmap(pixmap)
self.thread.run()
print "gggggggg"
def addImage(self,rect,pixmap):
self.viewer.setPixmap(pixmap)
print "aaaaaaaaaaaaa"
self.viewer.update(rect)
self.update()
def updateUi(self):
self.startButton.setEnabled(True)
class Worker(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
def __del__(self):
self.exiting = True
self.wait()
def run(self):#
while not self.exiting:
i=0
img=['1.jpg','2.jpg','3.jpg','4.jpg']
for i in img:
pixmap=QPixmap(i)
self.emit(SIGNAL("output(QRect,QPixmap)"),QRect(300,300,300,300),pixmap)
print "run............"
time.sleep(0.2)
#del Window.addImage()
if name == “main“:
app = QApplication(sys.argv)
window = Window()
print "ddd"
window.show()
print "cccc"
sys.exit(app.exec_())
显示不出来照片,但是后台运行,每按下一次ctrl+c就显示一张图片,是什么问题呢?