import pygame, pygame_menu, sys, random
#Main Window
screen_width = 1280
screen_height = 720
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Classics")
#Variables
bg = pygame.image.load("bg.png")
pong_btn_img = pygame.image.load("Button2.png")
pong_btn_img_p = pygame.image.load("pongpressed.png")
default_img_size = (300, 195)
pong_btn_img = pygame.transform.scale(pong_btn_img, default_img_size)
pong_btn_img_p = pygame.transform.scale(pong_btn_img_p, default_img_size)
#General setup
pygame.init()
clock = pygame.time.Clock()
#BUtton Class
class Button():
def __init__(self, x, y, image):
self.image = image
self.rect = self.image.get_rect()
self.rect.topleft = (x,y)
def draw(self):
# Get mouse pos
pos= pygame.mouse.get_pos()
#check mouse hover and click conditions
if self.rect.collidepoint(pos):
screen.blit(pong_btn_img_p, (self.rect.x, self.rect.y + 20))
if pygame.mouse.get_pressed()[0]:
exec(open("Game.py").read())
else:
#draw button on screen
screen.blit(self.image, (self.rect.x, self.rect.y))
# button instances
pong_btn = Button(525, 300, pong_btn_img)
while True:
#Handling Input
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
bg.set_alpha(20)
screen.blit(bg, (0,0))
pong_btn.draw()
#Updating the screen
pygame.display.flip()
clock.tick(60)
In the function draw(), in the if else statement, Im displaying an image which displays when the mouse hovers over the image and a different image if the mouse is not hovering over. When the mouse goes from not hovering to hovering the image fades out and in. I want it to disappear immediately