Pygame Window Not Responding After Entering If Statement
Solution 1:
You have to handle the events in the application loop. See pygame.event.get()
respectively pygame.event.pump()
:
For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.
Additionally you have to get the new mouse position in every frame with pygame.mouse.get_pos()
:
whileTrue:
pygame.event.pump()
mouse = pygame.mouse.get_pos()
# [...]
Alternatively you can use the MOUSEBUTTONDOWN
event:
ending_num = 1while ending_num != 0:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
mouse = event.pos
if10 < mouse[0] < 149and80 < mouse[1] < 130:
home_num = 0
ending_num = 0if10 < mouse[0] < 116and150 < mouse[1] < 200
home_num = 1
ending_num = 0
pygame.display.flip()
pygame.time.wait(70)
The MOUSEBUTTONDOWN
event occurs once when you click the mouse button and the MOUSEBUTTONUP
event occurs once when the mouse button is released. The pygame.event.Event()
object has two attributes that provide information about the mouse event. pos
is a tuple that stores the position that was clicked. button
stores the button that was clicked. Each mouse button is associated a value. For instance the value of the attributes is 1, 2, 3, 4, 5 for the left mouse button, middle mouse button, right mouse button, mouse wheel up respectively mouse wheel down.
Post a Comment for "Pygame Window Not Responding After Entering If Statement"