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 sorting array without inbuilt sort 
Python :: sys get current pythonpath 
Python :: replace value column by another if missing pandas 
Python :: python order 2d array by secode element 
Python :: convert two numpy array to pandas dataframe 
Python :: python column = sum of list of columns 
Python :: colab read xlsx 
Python :: how to get location of word in list in python 
Python :: powershell get list of groups and members 
Python :: python open pickle file 
Python :: how to convert input to uppercase in python 
Python :: force utf-8 encoding python 
Python :: sqlalchemy create engine PostgreSQL 
Python :: get path of notebook 
Python :: how to find index of second largest number in array python 
Python :: dataframe sort by column 
Python :: mark_safe django 
Python :: raise an APi error on django rest view 
Python :: python pandas dataframe from csv index column 
Python :: django validator min max value 
Python :: python move directory 
Python :: telethon get all channels 
Python :: how to make a window in tkinter 
Python :: win32api.mouse_event python 
Python :: binary search tree iterator python 
Python :: python colorama example 
Python :: remove nans from array 
Python :: tkinter input box 
Python :: Iterate through python string starting at index 
Python :: print var python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =