943,682 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 6785
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Jan 15th, 2006
0

pygame window not werking

Expand Post »
im using the python command prompt to enter these commands and after the window is shown. it becomes "not responding" which makes all later commands to it do absolutly nothing, including simply trying to resize the window with the mouse. this is how the code starts out...

Python Syntax (Toggle Plain Text)
  1. import os, sys, pygame
  2. from pygame.locals import *
  3.  
  4. pygame.init()
  5. window = pygame.display.set_mode((420,280))
  6. #everything here after does nothing to the window
  7. pygame.display.set_caption("my window")
  8. #etc...


im using windows XP
any ideas?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
senateboy is offline Offline
5 posts
since Jan 2006
Jan 16th, 2006
0

Re: pygame window not werking

Quote originally posted by senateboy ...
im using the python command prompt to enter these commands and after the window is shown. it becomes "not responding" which makes all later commands to it do absolutly nothing, including simply trying to resize the window with the mouse. this is how the code starts out...

Python Syntax (Toggle Plain Text)
  1. import os, sys, pygame
  2. from pygame.locals import *
  3.  
  4. pygame.init()
  5. window = pygame.display.set_mode((420,280))
  6. #everything here after does nothing to the window
  7. pygame.display.set_caption("my window")
  8. #etc...

im using windows XP
any ideas?
Pygame and Idle don't work very well together ...
Try to use something like drPython or Boa as an editor.

Peter.
http://www.pkort.nl
Reputation Points: 10
Solved Threads: 1
Newbie Poster
PKort is offline Offline
6 posts
since Oct 2005
Jan 17th, 2006
0

Re: pygame window not werking

Did you put the event loop in? This is a code sample of a very basic pygame program ...
python Syntax (Toggle Plain Text)
  1. import pygame
  2. from pygame.locals import *
  3.  
  4. yellow = (255,255,0) # RGB color tuple
  5.  
  6. # initialize screen
  7. pygame.init()
  8. screen = pygame.display.set_mode((350, 250))
  9. pygame.display.set_caption('Basic Pygame program')
  10.  
  11. # fill background
  12. background = pygame.Surface(screen.get_size())
  13. background = background.convert()
  14. background.fill(yellow)
  15.  
  16. # display some text
  17. font = pygame.font.Font(None, 36)
  18. text = font.render("Hello from Monty PyGame", 1, (10, 10, 10))
  19. textpos = text.get_rect()
  20. textpos.centerx = background.get_rect().centerx
  21. background.blit(text, textpos)
  22.  
  23. # blit everything to the screen
  24. screen.blit(background, (0, 0))
  25. pygame.display.flip()
  26.  
  27. # event loop
  28. while 1:
  29. for event in pygame.event.get():
  30. if event.type == QUIT:
  31. raise SystemExit
  32. screen.blit(background, (0, 0))
  33. pygame.display.flip()
Last edited by vegaseat; Aug 27th, 2007 at 7:58 pm. Reason: php-->python tag
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Aug 26th, 2007
0

Re: pygame window not werking

This Has been happening to me also
I want to learn how to program games and python was a good place to start, but every time i go to open a game window it opens as non responsive program and it makes me restart the python shell
I check my versions of pygame and python and they both match

Any help would be nice.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
jeff209 is offline Offline
1 posts
since Aug 2007
Aug 27th, 2007
0

Re: pygame window not werking

This would be a very basic pygame program, see if you can get that to work:
python Syntax (Toggle Plain Text)
  1. # fooling around with pygame --> draw/fill some rectangles
  2.  
  3. import pygame as pg
  4.  
  5. # initiate pygame first
  6. pg.init()
  7.  
  8. #create a 400x300 window
  9. screen = pg.display.set_mode((400, 300))
  10. # give it a title
  11. pg.display.set_caption('Draw/fill rectangles using pygame')
  12.  
  13. # some color constants
  14. white = 0xFFFFFF
  15. red = 0xFF0000
  16. green = 0x00FF00
  17. blue = 0x0000FF
  18. yellow = 0xFFFF00
  19.  
  20. #draw/fill a 77x33 rectangle in position x=250, y=50 (NW corner)
  21. screen.fill(white, (250, 50, 77, 33))
  22.  
  23. # more rectangles, vary color, size, position ...
  24. screen.fill(red, (30, 20, 70, 120))
  25. screen.fill(red, (140, 70, 90, 80))
  26. screen.fill(green, (150, 80, 70, 60))
  27. screen.fill(yellow, (200, 170, 150, 60))
  28. screen.fill(blue, (70, 200, 100, 70))
  29.  
  30. # hey, nothing gets displayed until one updates the screen
  31. pg.display.update()
  32.  
  33. # create the event loop to get things going
  34. # and specify an exit action (clicking on the window x)
  35. while True:
  36. for event in pg.event.get():
  37. if event.type == pg.QUIT:
  38. raise SystemExit
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Jan 3rd, 2009
0

Re: pygame window not werking

(Google turned up this thread for me...)

Same problem. I've tried it by typing right into Python, from the Windows shell (cmd.exe) and from a Cygwin bash shell, and got slightly different behavior in each case, but either way the PyGame window is unresponsive.

Python Syntax (Toggle Plain Text)
  1. import pygame
  2. a = pygame.display.set_mode((400, 300))
  3. # the surface window appears in both cases
  4. # it's grey and unavailable when I invoke python.exe (Windows version) from bash
  5. # the background is filled with black, but still unavailable when I invoke python.exe from CMD
  6. pygame.draw.circle(a, (255, 255, 255), (100, 100), 20)
  7. pygame.display.flip()
  8. # nothing happens
  9. pygame.quit()
  10. # surface window eventually disappears
  11. # under CMD -only-, the white circle appears briefly just before the window closes
  12. # under bash, no change is observed before closing

python.exe remains responsive throughout, but the graphics window is always in a 'busy' state, with the "busy" mouse cursor. It acquires the "(Not Responding)" caption after mouse or keyboard input.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Nuez_Jr is offline Offline
18 posts
since Oct 2004
Jan 3rd, 2009
1

Re: pygame window not werking

Are you guys putting the code into the interactive python interpreter or are you creating a separate .py file. When I started my first pygame project, I tried putting it in the interpreter and got an Not Responding window. Of course I just started python and pygame so what do I know .
Reputation Points: 15
Solved Threads: 1
Newbie Poster
ohblahitsme is offline Offline
9 posts
since Jan 2009
Jan 4th, 2009
0

Re: pygame window not werking

Just typing at the interpreter so far, but I'll try loading a file. BRB.

[Edit]
Okay, it works. This seems a bit off to me; if I call the update() function it ought to do what it's supposed to, regardless of where the interpreter's input is coming from.
Well, now I know. Thank you!!

Python Syntax (Toggle Plain Text)
  1. import pygame
  2.  
  3. pygame.init()
  4. a = pygame.display.set_mode((300, 300))
  5.  
  6. pygame.draw.circle(a, (255, 255, 255), (100, 100), 20)
  7. pygame.display.update()
  8.  
  9. foo = raw_input() # could just as well have used sleep()
  10.  
  11. pygame.quit()
  12. quit()
Last edited by Nuez_Jr; Jan 4th, 2009 at 3:31 am. Reason: checking out oblahitsme's recommendation
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Nuez_Jr is offline Offline
18 posts
since Oct 2004
Jan 4th, 2009
0

Re: pygame window not werking

I don't remember the full syntax, nor if it is actually what you are looking for but try
Python Syntax (Toggle Plain Text)
  1. pygame.display.flip()
Reputation Points: 15
Solved Threads: 1
Newbie Poster
ohblahitsme is offline Offline
9 posts
since Jan 2009
Jan 4th, 2009
0

Re: pygame window not werking

If you want the window to stay open and allow for a graceful exit procedure, you need to set up a simple event loop at the end of the program:
python Syntax (Toggle Plain Text)
  1. # a simple pygame example
  2. # creates a white circle on a black background
  3. # the event loop makes exit from the program easier
  4.  
  5. import pygame
  6.  
  7. pygame.init()
  8.  
  9. # create a 300 x 300 display window
  10. win = pygame.display.set_mode((300, 300))
  11.  
  12. white = (255, 255, 255)
  13. center = (100, 100)
  14. radius = 20
  15. pygame.draw.circle(win, white, center, radius)
  16.  
  17. # this puts the circle on the display window
  18. pygame.display.flip()
  19.  
  20. # event loop and exit conditions (windows x click)
  21. while True:
  22. for event in pygame.event.get():
  23. if event.type == pygame.QUIT:
  24. raise SystemExit
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
sneekula is offline Offline
2,413 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: tabarray input error: incomplete records
Next Thread in Python Forum Timeline: Annoying Error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC