I have done research about this problem, on internet, but there was no solution for my case... The window freezes when i try to close it with (X) button. And as I said I haven't came across any solution on other posts, so I came here to ask for help. Thank you.
#!/usr/bin/python
import sys
import pygame
# initialize
pygame.init()
# colors
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
# window size
w_size = [700,500]
main_screen = pygame.display.set_mode(w_size)
# Window info
pygame.display.set_caption("Cancer Cell")
# manage screen update time
clock=pygame.time.Clock()
#background image
bg_img = pygame.image.load("/img/bg_img.png").convert()
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# GAME LOGIC - BEGINNING
# -------- DRAWINGS - BEGINNING --------
main_screen.blit(bg_img, [0,0])
# -------- DRAWINGS - END ----------
# update screen
pygame.display.flip()
clock.tick(20) # 20 FPS limit for loop.
pygame.quit()
Your code work perfectly well on my platform. My platform: Scientific Linux 7 (RHEL 7) Python: 3.4.3 Pygame Version: 1.9.2b8 Window Manager: Gnome3
There is also probably bug in your code. The "/img/bg_img.png" suggest absolute path, it possible, but very uncommon :).
您的代码不仅在Linux Mate 17,python 2.7.6上按预期工作,而且它也可以与sys.exit()
而不是pygame.quit()
或者根本没有,即没有sys.exit()
或pygame.quit()
So it turns out that the IDLE is what was causing the problem... I tried to run the code from commandline and it worked perfectly!
The IDLE that I (was) using is called Wing101.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.