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

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

PREVIOUS NEXT
Code Example
Python :: add time to a datetime object 
Python :: axes color python 
Python :: set http response content type django 
Python :: how to add a function in python 
Python :: pd df drop columns 
Python :: import csv from google drive python 
Python :: what value do we get from NULL database python 
Python :: title() function in python 
Python :: python keyboardinterrupt 
Python :: django m2m .add 
Python :: python tkinter change color of main window 
Python :: pandas plot move legend 
Python :: install imgkit py 
Python :: python check if number is in range 
Python :: python exit for loop 
Python :: count unique values pandas 
Python :: run multiple function with multiprocessing python 
Python :: count decimal number python 
Python :: python check if class has function 
Python :: python file reading 
Python :: pandas dataframe to parquet s3 
Python :: list to string 
Python :: __str__() 
Python :: only get top 10 python dataframe 
Python :: display values on top of seaborn bar plot 
Python :: python tips and tricks 
Python :: data frame list value change to string 
Python :: python inner join based on two columns 
Python :: Add Border to input Pysimplegui 
Python :: intersect in python list 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =