I'm not sure if this is a problem with my code, with IDLE or maybe the modules, but when I run this program it sometimes crashes on start up. It usually happens once out of every three or four times. I'm confused because it doesn't always happen and it doesn't seem to make a difference if I create and blit the text surface within or outside the while loop. When it crashes, the pygame window opens but remains black and then all IDLE windows close without any error messages.
Here's the code:
import random, pygame, sys
from pygame.locals import*
pygame.init()
FPS = 30 #frames per second setting
fpsClock = pygame.time.Clock()
#variables
DISPLAYWIDTH = 800
DISPLAYHEIGHT = 500
WHITE = (255,255,255)
BLACK = (0,0,0)
#set up the window
DISPLAYSURF = pygame.display.set_mode((DISPLAYWIDTH, DISPLAYHEIGHT), 0, 32)
pygame.display.set_caption("Hello World!")
DISPLAYSURF.fill(WHITE)
# initialize font
myfont = pygame.font.SysFont("monospace", 100)
# render text
label = myfont.render("Hello World!", True, BLACK)
DISPLAYSURF.blit(label, (100, 100))
while True: #the main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)
I think the problem must be in the initialize font line because I've tried commenting out the render text lines and the problem still occurs. When I comment out all three lines handling the text, the program never crashes. Any ideas as to why this line would be seemingly randomly causing the program to crash? Thanks in advance!
EDIT: I am running Ubuntu 12.04, Python 3.2, and Pygame 1.9. I'm not sure how to run the program directly from the console without involving IDLE, but I have run it several times in Geany and so far it hasn't crashed.