Pygame, how to show window without loop? no loop=popupand close...

Discussion in 'Python' started by defn noob, Jun 28, 2008.

  1. defn noob

    defn noob Guest

    Im using PyGame to draw images of graphs and trees. Howver right now i
    am looping using:

    while 1:
    for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()

    screen.fill(screencolor)

    pygame.draw.circle(screen, linecolor, (500, 20), 12, 0)

    draw((500, 20), 3)

    pygame.display.flip()


    if i do

    screen.fill(screencolor)

    pygame.draw.circle(screen, linecolor, (500, 20), 12, 0)

    draw((500, 20), 3)

    pygame.display.flip()

    it just pops up and closes. how can i make it stay until i close it
    without using a loop?
     
    defn noob, Jun 28, 2008
    #1
    1. Advertising

  2. defn noob

    defn noob Guest

    Re: Pygame, how to show window without loop? no loop=popupandclose...

    right. im an idiot anyway. i can just draw the lines before entering
    the loop, problem solved...
     
    defn noob, Jun 28, 2008
    #2
    1. Advertising

  3. defn noob

    Carl Banks Guest

    Re: Pygame, how to show window without loop? no loop=popupandclose...

    On Jun 27, 10:58 pm, defn noob <> wrote:
    > right. im an idiot anyway. i can just draw the lines before entering
    > the loop, problem solved...


    Do not do that; it'll create a busy loop and use 100% of CPU. Use
    pygame.event.wait() instead. It waits for an event to occur, without
    using CPU cycles.


    Carl Banks
     
    Carl Banks, Jun 28, 2008
    #3
  4. defn noob

    defn noob Guest

    Re: Pygame, how to show window without loop? no loop=popupandclose...

    On 28 Juni, 08:32, Carl Banks <> wrote:
    > On Jun 27, 10:58 pm, defn noob <> wrote:
    >
    > > right. im an idiot anyway. i can just draw the lines before entering
    > > the loop, problem solved...

    >
    > Do not do that; it'll create a busy loop and use 100% of CPU. Use
    > pygame.event.wait() instead. It waits for an event to occur, without
    > using CPU cycles.
    >
    > Carl Banks





    pygame.init()
    screen = pygame.display.set_mode(size)

    while 1:
    for event in pygame.event.get():
    if event.type == pygame.QUIT: sys.exit()
    screen.fill(screencolor)
    draw((500, 20), 5)
    pygame.display.flip()
    pygame.event.wait()


    running that i cant close the program... what must i do? create an
    event at mouse click?
     
    defn noob, Jun 28, 2008
    #4
  5. defn noob

    Carl Banks Guest

    Re: Pygame, how to show window without loop? no loop=popupandclose...

    On Jun 28, 6:49 pm, defn noob <> wrote:
    > On 28 Juni, 08:32, Carl Banks <> wrote:
    >
    > > On Jun 27, 10:58 pm, defn noob <> wrote:

    >
    > > > right. im an idiot anyway. i can just draw the lines before entering
    > > > the loop, problem solved...

    >
    > > Do not do that; it'll create a busy loop and use 100% of CPU. Use
    > > pygame.event.wait() instead. It waits for an event to occur, without
    > > using CPU cycles.

    >
    > > Carl Banks

    >
    > pygame.init()
    > screen = pygame.display.set_mode(size)
    >
    > while 1:
    > for event in pygame.event.get():
    > if event.type == pygame.QUIT: sys.exit()
    > screen.fill(screencolor)
    > draw((500, 20), 5)
    > pygame.display.flip()
    > pygame.event.wait()
    >
    > running that i cant close the program... what must i do? create an
    > event at mouse click?


    A. pygame.event.wait is used in lieu of pygame.event.get

    B. RTFM. I suggested pygame.event.wait with the expectation that you
    would refer to the pygame documentation to learn how to use it
    yourself.


    Carl Banks
     
    Carl Banks, Jun 29, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Jensen
    Replies:
    1
    Views:
    5,244
    Matt Jensen
    Dec 16, 2005
  2. rantingrick

    [pygame-bug] Pygame.cdrom bug

    rantingrick, Jan 30, 2011, in forum: Python
    Replies:
    1
    Views:
    311
    Benjamin Kaplan
    Jan 30, 2011
  3. Iñaki Baz Castillo
    Replies:
    7
    Views:
    879
    Iñaki Baz Castillo
    Jan 12, 2010
  4. Walter Beierdonck

    Self.close() window without the dialog close?Yes/NO

    Walter Beierdonck, Apr 29, 2004, in forum: Javascript
    Replies:
    1
    Views:
    351
    Grant Wagner
    Apr 30, 2004
  5. Shang Wenbin

    close current window using window.close()

    Shang Wenbin, Sep 1, 2005, in forum: Javascript
    Replies:
    10
    Views:
    385
    Gérard Talbot
    Sep 2, 2005
Loading...

Share This Page