【问题标题】:Showing Consecutive images on a QLabel PyQt4在 QLabel PyQt4 上显示连续图像
【发布时间】:2017-09-07 17:57:07
【问题描述】:

我正在尝试在 QLabel 上显示连续图像 图像编号从 0000000 到 0000199 问题是 num 变量打印空字符串

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys, time

class Animation(QMainWindow):
    def __init__(self, parent=None):
        super(Animation, self).__init__(parent)

        self.resize(QSize(720, 480))

        self.imageViewer = QLabel(self)
        self.setCentralWidget(self.imageViewer)

        startBtn = QPushButton("start", self)
        startBtn.clicked.connect(self.start)
        self.statusBar().addWidget(startBtn)

    def start(self):
        i = 0
        while 1:
            num = ("0" * (len(str(i)) - 7)) + str(i)
            name = "frame" + num + ".png"
            print ("0" * (len(str(i)) - 7))
            self.imageViewer.setPixmap(QPixmap(name))
            if i == 199:
                break
            i += 1
            time.sleep(1)

app = QApplication(sys.argv)
test = Animation()
test.show()
app.exec_()

请帮忙

【问题讨论】:

  • 不,我改变主意了

标签: python python-2.7 pyqt pyqt4 qpixmap


【解决方案1】:

len(str(i)) - 7 返回一个负数。你需要交换它:

num = '0' * (7-len(str(i))) + str(i)

【讨论】:

  • 我认为问题不在于 num 因为图像仍然没有出现并且应用程序冻结
  • 您需要使用QThreads。主线程仅在准备就绪时才更新用户界面。因此,您需要另一个线程告诉主线程交换图像。
猜你喜欢
  • 1970-01-01
  • 2012-06-14
  • 2014-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多