如何更改此pyside2幻灯片?

时间:2019-05-16 21:25:08

标签: python python-3.x pyside pyside2

我找到并编辑了这个工作代码,该代码使用pyside2从收到的图像列表中显示幻灯片。

from PySide2.QtCore import *
import PySide2.QtGui as QtGui
from PySide2.QtWidgets import *
import time

class Slides(QWidget):
    def __init__(self, image_files, delay, parent=None):
        self.start = 0
        self.end = 0
        #create widget
        QWidget.__init__(self, parent)
        #create layout
        layout = QHBoxLayout()
        self.setLayout(layout)
        #get image files
        self.image_files = image_files
        #create label and laign
        self.label = QLabel(self)
        self.label.setAlignment(Qt.AlignCenter)
        #add label to layout
        layout.addWidget(self.label)

        #create timer
        self.timer = QBasicTimer()
        #create counter
        self.step = 0
        self.step2 = 1
        #slideshow delay
        self.delay = delay  # milliseconds
        self.setWindowTitle("StimPy Trial")
        #start time
        self.start = time.time()
        #start slideshow
        self.timerEvent()

        # run through slides

    def timerEvent(self, e=None):

        if self.step >= len(self.image_files):
            self.timer.stop()
            # end time
            self.end = time.time()
            print(self.end - self.start)
            exit(0)

        self.timer.start(self.delay, self)
        file = self.image_files[self.step]
        image = QtGui.QPixmap(file)
        self.label.setPixmap(image)
        self.step += 1

此代码显示具有给定图像和延迟的幻灯片显示,但是我希望它在每个图像前显示一些符号“ ***”,并在其后显示一小段空白屏幕。我试图通过将timerEvent()方法更改为

   def timerEvent(self):

    if self.step >= len(self.image_files):
        #end time
        self.end = time.time()
        print(self.end - self.start)
        exit(0)

    self.label.setFont(QtGui.QFont("Times", 25, QtGui.QFont.Bold))
    self.label.setText('***')
    time.sleep(0.5)
    file = self.image_files[self.step]
    image = QtGui.QPixmap(file)
    self.label.setPixmap(image)
    time.sleep(2)
    self.label.clear()
    time.sleep(0.25)
    self.step += 1
    self.timerEvent()

但不起作用。解决此问题的最佳方法是什么?也许有更好的方法可以完全创建此幻灯片演示?非常感谢您的帮助,在此先感谢您!

0 个答案:

没有答案