import sys import random import zipfile import webp from io import BytesIO from PyQt5.QtCore import QTimer from PyQt5 import QtWidgets, QtGui, QtCore from PIL import Image, ImageTk from PIL import ImageSequence import tempfile class Example(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): self.label = QtWidgets.QLabel(self) self.setCentralWidget(self.label) self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.FramelessWindowHint) self.zf = zipfile.ZipFile("gifs.zip", "r") self.gif_files = self.zf.namelist() self.timer = QTimer(self) self.timer.timeout.connect(self.show_random_gif) self.timer.start(1000) self.show_random_gif() def show_random_gif(self): if self.gif_files: gif_file = random.choice(self.gif_files) gif_bytes = self.zf.read(gif_file) with tempfile.NamedTemporaryFile(suffix='.gif', delete=False) as f: f.write(gif_bytes) file_name = f.name gif = Image.open(BytesIO(gif_bytes)) width, height = gif.width, gif.height screen_width = QtWidgets.QDesktopWidget().screenGeometry().width() screen_height = QtWidgets.QDesktopWidget().screenGeometry().height() self.setGeometry(screen_width - width, screen_height - height, width, height) movie = QtGui.QMovie(file_name, parent=self) movie.setCacheMode(QtGui.QMovie.CacheAll) self.label.setMovie(movie) transparency = gif.info.get("transparency") if transparency is not None: self.label.clearMask() self.label.setMask(QtGui.QBitmap(width, height)) self.label.clearMask() movie.start() else: self.label.clear() self.timer.stop() QTimer.singleShot(1000, self.timer.start) def setBackground(self, background_file): background = QtGui.QPixmap(background_file) palette = self.label.palette() palette.setBrush(self.label.backgroundRole(), QtGui.QBrush(background)) self.label.setPalette(palette) self.label.setAutoFillBackground(True) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) window = Example() window.show() sys.exit(app.exec_())