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

D

defn noob

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?
 
D

defn noob

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

Carl Banks

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
 
D

defn noob

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?
 
C

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top