用的是python2➕pyqt5
使用的图片呈现方式是用QLabel 然后再把图片转为QPixmap在QLabel上显示出来
现在碰到的问题是:
快速切换图片,比如每隔15ms来回切换两张图片;运行一段时间(毫无规律)后会出现卡在这两个界面其中一个,然后再设置成其他图片也不起作用了……但是程序没有报错 能正常执行 就是图片没有变化……
有哪位大佬有碰到过类似问题麽……怎么解决?万分感谢~
- ```
!/usr/bin/python
-- coding: utf-8 --
import sys
import time
import threading
from PyQt5.QtWidgets import (QWidget,
QLabel,
QGridLayout,
QPushButton,
QApplication)
from PyQt5.QtCore import Qt
class Test(QWidget):
def init(self, parent=None):
super(Test, self).init(parent)
self.is_fullscreen = False
self.switch_status = False
self.initUI()
def initUI(self):
self.lbl_image = QLabel(self)
grid = QGridLayout()
grid.addWidget(self.lbl_image, 0, 0)
grid.setSpacing(0)
grid.setContentsMargins(0, 0, 0, 0)
self.setLayout(grid)
self.setGeometry(300, 300, 350, 300)
# self.lbl_image.show()
self.setWindowTitle("DEMO001")
self.show()
def switch_iamge(self):
if self.switch_status:
print("111111111111111")
return
self.switch_status = True
for i in range(30):
for j in range(2):
time.sleep(0.016)
if j % 2 == 0:
self.lbl_image.setStyleSheet("background-color:black")
elif j % 2 == 1:
self.lbl_image.setStyleSheet("background-color:white")
self.switch_status = False
def keyPressEvent(self, event):
if event.key() == Qt.Key_F11:
if self.is_fullscreen:
self.showNormal()
self.is_fullscreen = False
else:
self.showFullScreen()
self.is_fullscreen = True
elif event.key() == Qt.Key_Q:
temp_thread = threading.Thread(target=self.switch_iamge)
temp_thread.setDaemon(True)
temp_thread.start()
if name == 'main':
app = QApplication(sys.argv)
ui = Test()
ui.show()
sys.exit(app.exec_())
```