欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PyQt5 - Lable中显示gif动画(+作为包导入不显示问题)

程序员文章站 2022-05-28 22:08:02
...

PyQt5 - Lable中显示gif动画(+作为包导入不显示问题)



导入模块:

PyQt5 - Lable中显示gif动画(+作为包导入不显示问题)


关键部分:

self.movie = QMovie("../icon/dinosaur.gif")
self.label.setMovie(self.movie)
self.movie.start()

 实例:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'D:\Qt\QT-Projects\实际项目\Oracle图书管理系统\PyCharm\Others_no_no\gif_show.ui'
#
# Created by: PyQt5 UI code generator 5.12.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import QMovie
import sys


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(647, 421)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(190, 110, 250, 150))
        self.label.setMinimumSize(QtCore.QSize(250, 150))
        self.label.setMaximumSize(QtCore.QSize(250, 150))
        self.label.setObjectName("label")
        MainWindow.setCentralWidget(self.centralwidget)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        
        self.movie = QMovie("../icon/dinosaur.gif")
        self.label.setMovie(self.movie)
        self.movie.start()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "GIF展示"))
        self.label.setStatusTip(_translate("MainWindow", "这是一只小恐龙"))
        self.label.setText(_translate("MainWindow", "TextLabel"))
        
        
if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(window)
    window.show()
    sys.exit(app.exec_())


 

【作为包导入时,需修改源文件的路径,以导入的地方作为源地址访问图片】

PyQt5 - Lable中显示gif动画(+作为包导入不显示问题)

 

相关标签: gif显示