Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

mouse in pygame

pygame.mouse.get_pos() #-> get the mouse cursor position on the screen in taple
#-> (x, y)

if event.type == pygame.MOUSEBUTTONDOWN:
    print(event.button)

#------------------------#
1 - left click
2 - middle click
3 - right click
4 - scroll up
5 - scroll down
#------------------------#
Comment

pygame mouse pos

 pygame.mouse.get_pos()
    get the mouse cursor position
    get_pos() -> (x, y)

    Returns the x and y position of the mouse cursor. 
    The position is relative to the top-left corner of the display. 
    The cursor position can be located outside of the display window,
    but is always constrained to the screen.
Comment

pygame mouse pos

x, y = pygame.mouse.get_pos()
print(x, y)
Comment

pygame point at mouse

import math

def rotate(self):
    mouse_x, mouse_y = pygame.mouse.get_pos()
    rel_x, rel_y = mouse_x - self.x, mouse_y - self.y
    angle = (180 / math.pi) * -math.atan2(rel_y, rel_x)
    self.image = pygame.transform.rotate(self.original_image, int(angle))
    self.rect = self.image.get_rect(center=self.position)
Comment

PREVIOUS NEXT
Code Example
Python :: python run in another thread decorator 
Python :: pandas count nans in column 
Python :: set allowed methods flask 
Python :: is python good for web development 
Python :: how to do a print statement in python 
Python :: iterate over classes in module python 
Python :: get count of values in column pandas 
Python :: how to convert adjacency list to adjacency matrix 
Python :: turn python script into exe 
Python :: numpy moving average 
Python :: in python how to use exp 
Python :: edit pandas row value 
Python :: dataframe to ftp 
Python :: print in python 
Python :: drop rows where specific column has null values 
Python :: Use module Crypto.Cipher.PKCS1_OAEP instead 
Python :: Matplotlib rotated x tick labels 
Python :: how to take date as input in python 
Python :: python array scalar multiplication 
Python :: how to put song in pygame 
Python :: input in one line python 
Python :: turn characters to alpgabetic numper python 
Python :: list files in python 
Python :: easy frequency analysis python 
Python :: transition from python 2 to 3 terminal 
Python :: socketserver python 
Python :: at=error code=H10 desc="App crashed" django 
Python :: python compare sets 
Python :: reverse python 
Python :: pairplot with selected field 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =