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

how to add mouse button in pygame

while...: #your loop
  
    button = pygame.Rect(cordX, cordY, width, height) #your bytton
    pygame.draw.rect(win, (0, 0, 0), button) #show button
    
     mx, my = pygame.mouse.get_pos() #mouse pos

	 if button.collidepoint((mx, my)): #cheak if mouse on button  
      	if pygame.mouse.get_pressed()[0]: #cheak if mouse is preesed
           # writh here what you want to happend
     pygame.display.update()
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 :: how to minimize command console python 
Python :: tkinter center frame 
Python :: pandas standardscaler 
Python :: python turtle sierpinski triangle 
Python :: python play mp3 in background 
Python :: tkinter start maximized 
Python :: convert dataframe column to float 
Python :: py for line in file 
Python :: how to make text bold in tkinter 
Python :: python parsing meaning 
Python :: django admin slug auto populate 
Python :: django filter not null 
Python :: how to see the functions of a library in python 
Python :: how to know python bit version 
Python :: python first two numbers 
Python :: how to raise a error in python 
Python :: modify dict key name python 
Python :: plot value counta 
Python :: oddlyspecific09123890183019283 
Python :: wordle hints 
Python :: sklearn version 
Python :: python plot cut off when saving 
Python :: python decimal number into 8 bit binary 
Python :: debconf: falling back to frontend: Readline Configuring tzdata 
Python :: python read_excel index_col 
Python :: get last element of dictionary python 
Python :: use sqlalchemy to create sqlite3 database 
Python :: runner up score through recurssion 
Python :: DateTime object representing DateTime in Python 
Python :: python check if number is complex 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =