1

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.

CLynnRose
  • 11
  • 2
  • What OS, what Python version, maybe what pygame version. Start IDLE from a console command line with `python -m idlelib` and you should see some error messages. Replace `python` with whatever needed to run specific python version on specific OS. Add `.idle` to `idlelib` for 2.7. Report errors by editing question. Do you get crashes if you run program from console directly, without involving IDLE? – Terry Jan Reedy Jun 24 '17 at 17:54
  • My operating system is Ubuntu 12.04 LTS, I'm using Python 3.2 and Pygame 1.9. When I try to start IDLE from the command line, it says its not installed. I don't know why. I will try to run the program without IDLE and edit my question with any new information. Thanks! – CLynnRose Jun 24 '17 at 18:07
  • @TerryJanReedy, I have edited my question to include the new information. I'm sorry but I'm not sure how to run the program from the console directly, and I wasn't able to start IDLE from the command line. Since it says it's not installed, should I try reinstalling with apt-get? – CLynnRose Jun 24 '17 at 18:22
  • I believe idlelib.__main__, needed for `-m idlelib` to work, was added after 3.2.0. If you are seeing IDLE windows, to ask the question you did, then it is installed. Run your program directly with `python3 path/to/yourfile.py`. To run with IDLE, try instead `python3 -m idlelib.idle` optionally add `path/to/yourfile.py` or open from within IDLE. – Terry Jan Reedy Jun 24 '17 at 18:46
  • Is it impossible to upgrade to recent python and IDLE within U 12.4? There have been a lot of bug fixes to both since. – Terry Jan Reedy Jun 24 '17 at 18:48
  • @TerryJanReedy Sorry, I've been trying to edit my post for the past 20 minutes, but the page won't load. Here's the new information I was trying to add: EDIT: I was able to launch IDLE from the terminal using `idle-python3.2` and run my program several times without crashing. The shell had a `===== RESTART =====` line each time the program ran but other than that it looked just like usual. – CLynnRose Jun 24 '17 at 18:56
  • @TerryJanReedy, I opened the program with the terminal directly using the python3 command and here too it runs fine. I tried again running the program with IDLE opened from the launcher and it still crashes sometimes that way. Is this just a problem with IDLE then and why doesn't it crash when IDLE is launched from the terminal? The version of IDLE I have seems to be the newest I can get using apt-get. Sorry for all this trouble, but this is still confusing to me. – CLynnRose Jun 24 '17 at 19:06
  • I thought about mentioning this from the start, but I wasn't sure if it was related. A while back I had trouble importing turtle, sometimes it would work and sometimes it said the module didn't exist. It also would sometimes run a long since closed turtle program when I ran any program that used turtle. So, probably these unexplained problems I'm having is just a buggy outdated IDLE and I should try to find and install a new one? – CLynnRose Jun 24 '17 at 19:39

0 Answers0