Pygame或Python中的透明窗口 [英] Transparent Window in Pygame or Python

查看:568
本文介绍了Pygame或Python中的透明窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的游戏的启动屏幕创建一个透明窗口.图像具有透明性,但是我无法使窗口透明(例如,在屏幕后面看到屏幕,桌面等.)我发现pygame不能执行任何操作.是否可以使用任何外部库来实现这一目标?顺便提一句.这完全是一个Linux项目.因此,特定于操作系统也可以.

Im trying to make a transparent window for a splash screen for my game. The image has transparency but I cant make the window transparent(like see screen, desktop, etc.. behind it) All I've found is a no-go with pygame. Is there any external libraries that I could pull from to make this possible? BTW. This is entirely a Linux project. So os specific are ok too.

#Splash Screen
screen = pygame.display.set_mode((680,300), NOFRAME)
splashbg = pygame.image.load("Images/SplashBG.png")
font = pygame.font.Font(None, 36)

pygame.mixer.music.load("OriginalEnd.mp3")
pygame.mixer.music.play(-1)

screen.blit(splashbg,(0,0))
loadingtext = font.render("Loading...", 1, (255,255,255))
screen.blit(loadingtext, (200,250))
pygame.display.flip()
pygame.time.delay(4000)

推荐答案

您始终可以使用假装透明性对贫民窟进行版本化.无论如何,它都不是理想的解决方案,但它可能会起作用.

You could always ghetto version it with pretend transparency. It's not an ideal solution by any means, but it may work..

在启动屏幕之前,请使用PIL拍摄桌面快照,先将其钝化,然后在其上绘制透明图像.这样,它至少会给幻觉透明性.

Before you launch your screen, use PIL to take a snapshot of the desktop, blit that first, and then draw your transparent image over it. That way it'll at least give the illusion of transparency.

有点像:

import ImageGrab, Image 

im = Imagegrab.grab()
im.save('faux_trans.png','png')

for_trans = pygame.image.load('faux_trans.png').convert()

splash = pygame.image.load.... 

screen.blit(for_trans, (0,0))

# and so on. 

就像我说的那样,这不是最好的解决方案,但是如果您启动游戏NOFRAME或FULLSCREEN,也许可以摆脱它! :)

Like I said, not the greatest solution, but if you launch your game NOFRAME, or FULLSCREEN, you may be able to get away with it! :)

这篇关于Pygame或Python中的透明窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆