Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

on click on image pygame

import pygame

pygame.init()
screen = pygame.display.set_mode((350, 400))
pygame.display.set_caption('clicked on image')
redSquare = pygame.image.load("images/red-square.png").convert()

x = 20; # x coordnate of image
y = 30; # y coordinate of image
screen.blit(redSquare ,  ( x,y)) # paint to screen
pygame.display.flip() # paint screen one time

running = True
while (running):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.MOUSEBUTTONDOWN:
            x, y = event.pos
            if redSquare.get_rect().collidepoint(x, y):
                print('clicked on image')
 
PREVIOUS NEXT
Tagged: #click #image #pygame
ADD COMMENT
Topic
Name
8+2 =