pyqy小记|生成gif并嵌入到GUI中
生成gif,嵌入到标签QLabel中
def compose_gif(self):
"""生成gif
"""
jpgPath_List = []
jpgList = os.listdir("./temp save files")
for jpgName in jpgList:
absolutePath = os.path.join("./temp save files/", jpgName)
jpgPath_List.append(absolutePath)
gif_images = []
for path in jpgPath_List:
gif_images.append(imageio.imread(path))
imageio.mimsave("./temp save files/test.gif", gif_images, fps=2)
self.gif = QMovie('./temp save files/test.gif')
gif_tab = QtWidgets.QWidget()
gif_tab.setObjectName('gif_tab')
self.tabWidget.addTab(gif_tab, 'GIF')
gif_verticalLAYOUT = QtWidgets.QVBoxLayout(gif_tab)
gif_verticalLAYOUT.setObjectName('gif_verticalLAYOUT')
self.gifLabel = QtWidgets.QLabel(gif_tab)
self.gifLabel.setObjectName('gifLabel')
gif_verticalLAYOUT.addWidget(self.gifLabel)
self.tabWidget.setCurrentWidget(gif_tab)
self.gifLabel.setMovie(self.gif)
self.gif.start()
self.gifLabel.show()
播放/暂停gif
def pauseGif(self):
self.gif.setPaused(True)
def playGif(self):
self.gif.setPaused(False)