В следующем коде методы Show () и Click () - это методы, которые я создал для класса кнопки
Код: Выделить всё
def run(self):
got_mouse_click = False
while True:
for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]):
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN)
self.screen.fill("aqua")
self.game_button.show(self.screen)
self.options_button.show(self.screen)
self.quit_button.show(self.screen)
if self.game_button.click():
self.save_menu.run()
elif self.options_button.click():
self.options.run()
elif self.quit_button.click():
pygame.quit()
sys.exit()
pygame.display.flip()
< /code>
Это метод click (): < /p>
def click(self, *, button_to_click=1, delete_events:bool=True): #left click is 1, middle button click is 2, right click is 3, mouse wheel up is 4, mouse wheel down is 5
x, y = pygame.mouse.get_pos()
if self.rect.collidepoint(x, y):
for event in pygame.event.get(eventtype=pygame.MOUSEBUTTONDOWN):
# puts the events back in the event list if delete_events = False
if not delete_events: pygame.event.post(event)
# checks for mouse click
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == button_to_click:
self.execute()
return True
return False
Код: Выделить всё
for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]):
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN)
pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN)
for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]):
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
< /code>
и < /p>
for event in pygame.event.get(exclude=[pygame.MOUSEBUTTONDOWN]):
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.event.clear(eventtype = pygame.MOUSEBUTTONDOWN)
< /code>
.
У кого -то есть представление о том, почему это происходит? это?
Подробнее здесь: https://stackoverflow.com/questions/796 ... a-for-loop