Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pygame change color mouse hover

# Imports
import sys
import pygame

# Configuration
pygame.init()
fps = 60
fpsClock = pygame.time.Clock()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))

# Before Main loop
rect = pygame.Rect(10, 10, 100, 60)
print(rect.width)
btn_surface = pygame.Surface(
    (rect.width, rect.height)
)

normal_color = (200, 100, 100)
hover_color = (100, 200, 100)

# Game loop.
while  True:
    screen.fill((20, 20, 20))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # In the Main loop
    if rect.collidepoint(pygame.mouse.get_pos()):
        btn_surface.fill(hover_color)
    else:
        btn_surface.fill(normal_color)

    screen.blit(btn_surface, rect)

    pygame.display.flip()
    fpsClock.tick(fps)
Comment

PREVIOUS NEXT
Code Example
Python :: Print Table Using While Loop In Python 
Python :: python -m pip install --upgrade 
Python :: python for get index and value 
Python :: add authorization header in python requests 
Python :: how to align text in tkinter 
Python :: how to find the calendar week python 
Python :: log scale seaborn 
Python :: How to use tqdm with pandas apply 
Python :: ver todas linhas dataframe pandas 
Python :: python find most occuring element 
Python :: bar chart with seaborn 
Python :: fibonacci python 
Python :: how to sort in pandas 
Python :: get distance between 2 multidimentional point in python 
Python :: how to blit text in pygame 
Python :: define a column as index pandas 
Python :: how to minimize command console python 
Python :: pandas plot disable legend 
Python :: how to change font sizetkniter 
Python :: python parsing meaning 
Python :: python create n*n matrix 
Python :: python file extension 
Python :: python first two numbers 
Python :: maximizar ventana tkinter python 
Python :: extract text from a pdf python 
Python :: python file basename 
Python :: django jinja subset string 
Python :: join two set in python 
Python :: how to display qr code in python 
Python :: iterative binary search python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =