下面的代码是一个简单的Python代码,PyQt5用于显示GIF。我有两个显示器,一个是imac 5k,另一个是QHD显示器。很难理解在不同监视器上运行Python文件的情况之间的CPU使用差异。即使我将PyQt窗口全屏显示,CPU使用率也会变得更高。为什么会这样?
from PyQt5.QtWidgets import QApplication, QDesktopWidget, QMainWindow, QLabel
from PyQt5 import QtGui
from PyQt5.QtCore import QTimer
import sys
class gifplayer(QMainWindow):
def __init__(self):
super(gifplayer, self).__init__()
self.mainwidget = QMainWindow(self)
self.setFixedSize(480, 330)
self.center()
self.timer = QTimer(self)
self.timer.timeout.connect(self.play)
self.timer.start(2650)
self.player = QLabel(self)
self.movie = QtGui.QMovie("./test.gif")
self.player.setMovie(self.movie)
self.player.setGeometry(0, 0, 480, 330)
self.movie.start()
self.show()
def play(self):
self.movie.start() # those lines
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
app = QApplication(sys.argv)
ex = gifplayer()
sys.exit(app.exec_())