My pygame crashes when I double click on its window's icon

Viewed 45

my script crashes with:

Fatal Python error: pygame_parachute: (pygame parachute) Segmentation FaultPython runtime state: initialized

Current thread 0x00001718 (most recent call first):
  File "c:\Users\tee_c\Projects\abc\ABC.py", line 10 in <module>

Extension modules: pygame.base, pygame.constants, pygame.rect, pygame.rwobject, pygame.surflock, pygame.color, pygame.bufferproxy, pygame.math, pygame.surface, pygame.display, pygame.draw, pygame.event, pygame.imageext, pygame.image, pygame.joystick, pygame.key, pygame.mouse, pygame.time, pygame.mask, pygame.pixelcopy, pygame.transform, pygame.font, pygame.mixer_music, pygame.mixer, pygame.scrap, numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, PIL._imaging, pygame._freetype, win32api, _win32sysloader (total: 42);

when I double click on the png icon of the window. Here is my code.

import easygui as eg
eg.msgbox(msg="press q when window opens to start script(not game).",title="note")
pygame.init()
logoIMG = pygame.image.load('ABClogo.png')
canvas=pygame.display.set_mode((700,500))
pygame.display.set_caption('ABC(game)')
pygame.display.set_icon(logoIMG)
while True:
    pygame.draw.rect(canvas, "red", pygame.Rect(30, 30, 60, 60))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        elif event.type==pygame.KEYDOWN:
            if event.key == pygame.K_q:
                pygame.display.flip()
1 Answers

The indentation on the pygame.display.flip() is wrong. The .flip() writes all the window changes to the GUI, and is normally always called every loop iteration.

This version works for me (I don't have/want easygui):

import pygame

#import easygui as eg
#eg.msgbox(msg="press q when window opens to start script(not game).",title="note")

pygame.init()
logoIMG = pygame.image.load('ABCLogo.png')
canvas=pygame.display.set_mode((700,500))
pygame.display.set_caption('ABC(game)')
pygame.display.set_icon(logoIMG)

running = True
while running:
    pygame.draw.rect(canvas, "red", pygame.Rect(30, 30, 60, 60))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        elif event.type==pygame.KEYDOWN:
            if event.key == pygame.K_q:
                print('q')
    pygame.display.flip()
pygame.quit()
Related