promotion image of download ymail app
Promoted

[Python] Pygame: How do I stop event from happening?

import sys

import pygame

pygame.init()

screen = pygame.display.set_mode((640, 480))

fps = pygame.time.Clock()

angle = 0

done = False

startpoint = pygame.math.Vector2(100, 240)

endpoint = pygame.math.Vector2(50, 0)

def open():

    if angle < 85:

        current_endpoint = startpoint + endpoint.rotate(-angle)

        pygame.draw.line(screen, (255, 255, 255), startpoint, current_endpoint, 2)

def close():

    startpoint = pygame.math.Vector2(100, 240)

    endpoint = pygame.math.Vector2(0, -50)

    current_endpoint = startpoint + endpoint.rotate(angle)

    pygame.draw.line(screen, (255, 255, 255), startpoint, current_endpoint, 2)

while not done:

    pygame.display.set_caption(str(angle))

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            done = True

    screen.fill((0, 0, 0))

    angle = (angle + 5) % 90

    close()

    pygame.display.flip()

    fps.tick(10)

pygame.quit()

sys.exit()

It's like a clock; a line spins in circles. But I only want it to spin 90 degrees and I only want it to happen once

Update:

When I say 'stop happening', I really mean 'stop repeating' since it's doing the same thing over and over

2 Answers

Relevance
  • 2 months ago
    Favorite Answer

    You already found your problem.  Good work!

    One suggestion:  If you want to get rid of that version and hello/contribute message, put a variable named PYGAME_HIDE_SUPPORT_PROMPT in your environment.  The value doesn't matter, only the presence of the name is tested.

    You can do this once for all programs using environment tools for your OS, or you can do it just for the current program by adding a couple of statement before importing pygame:

    import os # if it's not there already

    os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = 'Y'

    import pygame

    • Thanks for the advice! I'm new to pygame so I've just been looking at different example programs to see how it works

    • Commenter avatarLogin to reply the answers
  • I found the solution, just had to remove '% 90' 

    Hours of my short life wasted

    • ...Show all comments
    • husoski
      Lv 7
      2 months agoReport

      Have fun with your foray into pygame.  Right now, though, the pygame.org website is down, and that's where the best documentation is.  It looks like someone forgot to pay a hosting bill or something...  :^(

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.