I want to create an tranparent button and text on the screen, i search for the way to do this, the fourth RGB parameter and set_alpha can transparent the color
So i use self.button_color=(0,100,100,128) to set the button and self.text.set_alpha(128) to change the color on text
But nothing change when i run the scripts
Here's the code:
#!/usr/bin/python
import sys,os
import pygame
class Setting():
def __init__(self,width,height):
self.w=width
self.h=height
self.flag=pygame.RESIZABLE
self.screen=pygame.display.set_mode((self.w,self.h),self.flag)
self.screen_rect=self.screen.get_rect()
pygame.display.set_caption("Test")
class Button():
def __init__(self,setting,text):
self.width,self.height = 400,100
self.button_color=(0,100,100,128)
self.text_color=(255,0,0)
self.text = pygame.font.Font(None,100).render(text,True,self.text_color)
self.text.set_alpha(128)
self.rect = pygame.Rect(0,0,self.width,self.height)
self.rect.center = setting.screen_rect.center
self.text_rect = self.text.get_rect()
self.text_rect.center = self.rect.center
def draw_button(self,setting):
setting.screen.fill(self.button_color,self.rect)
setting.screen.blit(self.text,self.text_rect)
def game():
pygame.init()
setting=Setting(1200,800)
button=Button(setting,'PLAY')
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
setting.screen.fill((0,0,0))
button.draw_button(setting)
pygame.display.flip()
game()
