Python/PyQt6 slideshow run on Windows 11

A simple Python/PyQt6 SlideShow to display jpg images in images folder. It's generated by Copilot, except the lines marked in blue. Tested on Windows 11 with PyQt6 installed in Python virtual environment.


pyqt6_slideshow.py
import sys
import glob
from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QWidget
from PyQt6.QtGui import QPixmap
from PyQt6.QtCore import QTimer
from PyQt6.QtCore import Qt

class SlideShowWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Image Slide Show")
        self.image_label = QLabel(self)
        self.image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
        layout = QVBoxLayout()
        layout.addWidget(self.image_label)
        container = QWidget()
        container.setLayout(layout)
        self.setCentralWidget(container)
        self.image_files = glob.glob("images/*.jpg")
        self.current_index = 0
        self.show_image()
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.show_next_image)
        self.timer.start(2000)

    def show_image(self):
        if self.image_files:
            pixmap = QPixmap(self.image_files[self.current_index])
            #self.image_label.setPixmap(pixmap.scaled(self.image_label.size(), Qt.AspectRatioMode.KeepAspectRatio))
            self.image_label.setPixmap(pixmap.scaled(1024, 1024,
                                                     Qt.AspectRatioMode.KeepAspectRatio))
            
    def show_next_image(self):
        self.current_index = (self.current_index + 1) % len(self.image_files)
        self.show_image()

app = QApplication(sys.argv)
window = SlideShowWindow()
window.show()
sys.exit(app.exec())



Comments

Popular posts from this blog

480x320 TFT/ILI9488 SPI wih EP32C3 (arduino-esp32) using Arduino_GFX Library

my dev.tools - FNIRSI 2C23T 3-in-1 Dual Channel Oscilloscope/Multimeter/Signal Generator