我想在背景完全透明的pyglet上运行gif,因此只有gif的形状会显示在屏幕上,而背景将是执行程序时已经存在的屏幕,有什么方法可以这样吗?
from threading import *
import time
import pyglet
class Gif(Thread):
def run(self):
animation = pyglet.image.load_animation("gif3.gif")
animSprite = pyglet.sprite.Sprite(animation)
animSprite.opacity = 200
w = animSprite.width
h = animSprite.height
window = pyglet.window.Window(width=w, height=h,
style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS)
platform = pyglet.window.get_platform()
display = platform.get_default_display()
screen = display.get_default_screen()
pyglet.gl.glEnable(pyglet.gl.GL_BLEND)
pyglet.gl.glBlendFunc(pyglet.gl.GL_SRC_ALPHA, pyglet.gl.GL_ONE_MINUS_SRC_ALPHA)
window.set_location((screen.width-w)//2, (screen.height-h)//2)
# r,g,b,alpha = 1, 1, 1, 1
# pyglet.gl.glClearColor(r,g,b,alpha)
@window.event
def on_draw():
window.clear()
animSprite.draw()
pyglet.app.run()
gif = Gif()
gif.daemon = True
gif.start()
for i in range(5):
print(i)
time.sleep(2)
我总是得到黑色或白色的背景。