简体   繁体   English

Pygame或Python中的透明窗口

[英]Transparent Window in Pygame or Python

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. 图像有透明度但我不能让窗口透明(比如看到屏幕,桌面等等......)我发现所有这些都与pygame无关。 Is there any external libraries that I could pull from to make this possible? 我可以从中获取任何外部库以实现此目的吗? BTW. BTW。 This is entirely a Linux project. 这完全是一个Linux项目。 So os specific are ok too. 因此,os具体也可以。

#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.. 无论如何,它不是一个理想的解决方案,但它可能有效..

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. 在启动屏幕之前,使用PIL拍摄桌面快照,首先进行blit,然后在其上绘制透明图像。 That way it'll at least give the illusion of transparency. 这样,它至少会给人一种透明的幻觉

Something kind of like: 有点像:

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. 

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! 就像我说的那样,不是最好的解决方案,但如果你推出游戏NOFRAME,或者FULLSCREEN,你可能会侥幸逃脱它! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM