Search
 
SCRIPT & CODE EXAMPLE
 

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')
Comment

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')
Comment

PREVIOUS NEXT
Code Example
Python :: youtube upload python 
Python :: find a file in python 
Python :: python regex find first 
Python :: datetime year python 
Python :: Django - include app urls 
Python :: convert xml to dataframe python 
Python :: python convert string to date 
Python :: drop nulll python 
Python :: FileExistsError: [Errno 17] File exists: 
Python :: compute eigenvalue python 
Python :: python hello world 
Python :: python oprators 
Python :: add colorbar to figure matplotlib line plots 
Python :: save dataframe to csv 
Python :: python style console output 
Python :: multiply all values in column pandas 
Python :: save a file as a pickle 
Python :: tkinter frame inside frame 
Python :: exec to return a value python 
Python :: Creating a list with list comprehensions 
Python :: python horizontal line 
Python :: tkinter button foreground color click 
Python :: rename column pandas 
Python :: copy a list python 
Python :: split a given number in python 
Python :: django redirect to external url 
Python :: dataframe column data type 
Python :: sklearn train_test_split 
Python :: case statement in pandas 
Python :: how to merge two dataframes 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =