做了窗口背景透明和无边框,直接在编译器页面进行现实的
代码如下:
这段代码主要是为了显示链式动画图片,主要用到了QTimer以及QPixmap的copy方法:
from PyQt5 import QtCore
from PyQt5.Qt import *
import sys
class DEMO(QLabel):
def __init__(self):
super(DEMO,self).__init__()
self.initUI()
self.list_images=[]
self.int_totalIndex = 0
#self.init_list_images("./蓝色边框特效_177_98_14.png",14)
self.timer=QTimer(self)
self.int_currentIndex=0
self.int_loop=-1
def initUI(self):
self.resize(400,200)
self.setScaledContents(1)
#self.setAttribute(Qt.WA_NoSystemBackground)
self.setWindowFlags(Qt.FramelessWindowHint | Qt.Tool|Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground) # 透明
#self.setStyleSheet("background-color:rgba(15,122,155,0)")
#就是设置链式动画图片及其数量
def init_list_images(self,str_path,int_count):
self.int_totalIndex=int_count
pxmp_raw=QPixmap(str_path)
int_singleWidth=int(pxmp_raw.width()/int_count)
for i in range(int_count):
self.list_images.append(pxmp_raw.copy(i*int_singleWidth,0,int_singleWidth,pxmp_raw.height()))
#内部,更新label上的图片
def update(self):
if self.int_loop==-1:
self.int_currentIndex+=1
if self.int_currentIndex>(self.int_totalIndex-1):
self.int_currentIndex=0
self.setPixmap(self.list_images[self.int_currentIndex])
#开始显示动画,可以设置间隔和循环
def begin(self,int_interval=100,int_loop=-1):
self.int_loop=int_loop
self.timer=QTimer(self)
self.timer.setInterval(int_interval)
self.timer.start()
self.timer.timeout.connect(self.update)
if __name__=="__main__":
app=QApplication(sys.argv)
p=DEMO()
p.show()
p.init_list_images("./火把_100_100_11.png",11)
p.resize(QSize(200,200))
p.move(100,100)
p.begin(50)
sys.exit(app.exec_())
素材图片如下:
效果:
版权声明:本文为realliyuhao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。