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...

import os, sys, pygame
from pygame.locals import *

pygame.init()
window = pygame.display.set_mode((420,280))
#everything here after does nothing to the window
pygame.display.set_caption("my window")
#etc...

im using windows XP
any ideas?

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...

import os, sys, pygame
from pygame.locals import *

pygame.init()
window = pygame.display.set_mode((420,280))
#everything here after does nothing to the window
pygame.display.set_caption("my window")
#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

Did you put the event loop in? This is a code sample of a very basic pygame program ...

import pygame
from pygame.locals import *
 
yellow = (255,255,0) # RGB color tuple
 
# initialize screen
pygame.init()
screen = pygame.display.set_mode((350, 250))
pygame.display.set_caption('Basic Pygame program')
 
# fill background
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill(yellow)
 
# display some text
font = pygame.font.Font(None, 36)
text = font.render("Hello from Monty PyGame", 1, (10, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)
 
# blit everything to the screen
screen.blit(background, (0, 0))
pygame.display.flip()
 
# event loop
while 1:
    for event in pygame.event.get():
        if event.type == QUIT:
            raise SystemExit
        screen.blit(background, (0, 0))
        pygame.display.flip()

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.

This would be a very basic pygame program, see if you can get that to work:

# fooling around with pygame --> draw/fill some rectangles

import pygame as pg

# initiate pygame first
pg.init()

#create a 400x300 window
screen = pg.display.set_mode((400, 300))
# give it a title
pg.display.set_caption('Draw/fill rectangles using pygame')

# some color constants
white = 0xFFFFFF
red = 0xFF0000
green = 0x00FF00
blue = 0x0000FF
yellow = 0xFFFF00

#draw/fill a 77x33 rectangle in position x=250, y=50 (NW corner)
screen.fill(white, (250, 50, 77, 33))

# more rectangles, vary color, size, position ...
screen.fill(red, (30, 20, 70, 120))
screen.fill(red, (140, 70, 90, 80))
screen.fill(green, (150, 80, 70, 60))
screen.fill(yellow, (200, 170, 150, 60))
screen.fill(blue, (70, 200, 100, 70))

# hey, nothing gets displayed until one updates the screen
pg.display.update()

# create the event loop to get things going
# and specify an exit action (clicking on the window x)
while True:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            raise SystemExit

(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.

import pygame
a = pygame.display.set_mode((400, 300))
# the surface window appears in both cases
# it's grey and unavailable when I invoke python.exe (Windows version) from bash
# the background is filled with black, but still unavailable when I invoke python.exe from CMD
pygame.draw.circle(a, (255, 255, 255), (100, 100), 20)
pygame.display.flip()
# nothing happens
pygame.quit()
# surface window eventually disappears
# under CMD -only-, the white circle appears briefly just before the window closes
# 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.

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 :P.

commented: Don't know -why- it worked, but running a saved script instead of interactive input did the trick! +5

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!!

import pygame

pygame.init()
a = pygame.display.set_mode((300, 300))

pygame.draw.circle(a, (255, 255, 255), (100, 100), 20)
pygame.display.update()

foo = raw_input() # could just as well have used sleep()

pygame.quit()
quit()

I don't remember the full syntax, nor if it is actually what you are looking for but try

pygame.display.flip()

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:

# a simple pygame example
# creates a white circle on a black background
# the event loop makes exit from the program easier

import pygame

pygame.init()

# create a 300 x 300 display window
win = pygame.display.set_mode((300, 300))

white = (255, 255, 255)
center = (100, 100)
radius = 20
pygame.draw.circle(win, white, center, radius)

# this puts the circle on the display window
pygame.display.flip()

# event loop and exit conditions (windows x click)
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            raise SystemExit

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 :P.

Why not try to run it from IDEs like Drpython, or Wing 101 and tell us the progress

I don't remember the full syntax, nor if it is actually what you are looking for but try

pygame.display.flip()

If I've understood correctly, flip() is specifically for double-buffered surfaces ... or more specifically, for changing buffers on surfaces for which you're taking advantage of SDL double buffering in the first place.

I've since found another tutorial that enlightened me re: the Not Responding window. It turns out the reason the window is 'not responding' is because our code is literally not responding to its event queue. Mouse clicks, mouse moves, key presses, and in fact lots of other random crud too, all pile up in the Windows Message Queue, and when Windows detects that a program isn't processing its messages (and thereby removing them from the queue - kind of like not reading your mail and letting it pile up in the mailbox), then Windows marks that window "Not Responding".

pygame.event.get()
# returns a list of events. I haven't read ahead enough to know how to
# deal with them individually, i.e. look for typed letters
# (as opposed to scanning the keyboard contstantly, hoping you don't miss one...)
# ... but I have determined that calling this function:
#     - clears the message queue
#     - makes the game window's 'Not Responding' tag go away
#     - allows all the drawn changes to show up

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 :P.

For a program run from a file, even if it doesn't do any event processing, the window's lifetime will be so short that it probably won't have a chance for any unprocessed events to pile up. So that way a program that is incorrect in that it does not check for events will still appear to work. I suspect that the reason I could see my circle drawn onscreen just before the window went away was that part of pygame.quit()'s job is to throw away any remaining events in the queue, and when that happens the drawing updates can go through as the last things to happen before the window dies.

Try this from the interpreter (after creating a window)

while True:
 print pygame.event.wait()

to see all the events a window typically recieves.

i have discovered that if you add pygame.display.flip()...

import sys, pygame
from pygame.locals import *

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

the display will show the screen black like its supposed to , !but it will still will say not responding.if you add a while loop to the end it will work 100%%

import pygame,sys
from pygame.locals import*

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

while 1:
    for event in pygame.event.get():
        if event.type==QUIT:
            pygame.quit()
            sys.exit()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.