By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?
Jun 28 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

defn noob wrote:
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?
You need the loop, because without it, the script would reach the
end-of-file and stop executing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhlo4QACgkQLMI5fndAv9izMwCeKVOyPh74vU Zwau+Qsnns6NeY
PP0An03w+GQQ2neR7Gh779uJcqN56Cpd
=nlGj
-----END PGP SIGNATURE-----
Jun 28 '08 #2

P: n/a
right. im an idiot anyway. i can just draw the lines before entering
the loop, problem solved...
Jun 28 '08 #3

P: n/a
On Jun 27, 10:58 pm, defn noob <circularf...@yahoo.sewrote:
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
Jun 28 '08 #4

P: n/a
On 28 Juni, 08:32, Carl Banks <pavlovevide...@gmail.comwrote:
On Jun 27, 10:58 pm, defn noob <circularf...@yahoo.sewrote:
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?
Jun 28 '08 #5

P: n/a
On Jun 28, 6:49 pm, defn noob <circularf...@yahoo.sewrote:
On 28 Juni, 08:32, Carl Banks <pavlovevide...@gmail.comwrote:
On Jun 27, 10:58 pm, defn noob <circularf...@yahoo.sewrote:
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
Jun 28 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.