Probleme mit dem schließen des Fensters
Verfasst: Dienstag 23. Juni 2015, 08:45
Hallo zusammen,
ich brauch mal wieder eure Hilfe.
Ich versuche mich gerade in PyGame einzuarbeiten, ich hab das Beispiel-Programm "catanimation.py" von http://inventwithpython.com/pygame/chapter2.html probiert.
Das macht es was es sol, nun wollte ich den Code so erweitern, dass ich selber das Bild bewegen kann. Das macht es auch, ABER nun kann ich, wenn ich das Programm in PyCharm ausführe
nicht mehr über den "Schließen-Button" schließen.
Hier mein Code:
Könnt Ihr mir sagen wo mein Fehler liegt, bzw. was ich übersehe hab.
Vielen Dank im Voraus.
Grüße JohannesGolf
ich brauch mal wieder eure Hilfe.
Ich versuche mich gerade in PyGame einzuarbeiten, ich hab das Beispiel-Programm "catanimation.py" von http://inventwithpython.com/pygame/chapter2.html probiert.
Das macht es was es sol, nun wollte ich den Code so erweitern, dass ich selber das Bild bewegen kann. Das macht es auch, ABER nun kann ich, wenn ich das Programm in PyCharm ausführe
nicht mehr über den "Schließen-Button" schließen.
Hier mein Code:
Code: Alles auswählen
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 60
pfs_clock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((400, 300), 0 , 32)
pygame.display.set_caption('Animation')
BLACK = (0, 0, 0)
cat_img = pygame.image.load('cat.png')
cat_x = 10
cat_y = 15
while True:
DISPLAYSURF.fill(BLACK)
key_events = pygame.event.get()
for action in key_events:
if action.type == pygame.KEYDOWN:
if action.key == pygame.K_LEFT:
cat_x -= 15
if action.key == pygame.K_RIGHT:
cat_x += 15
if action.key == pygame.K_DOWN:
cat_y += 15
if action.key == pygame.K_UP:
cat_y -= 15
if cat_x > 280:
cat_x = 0
if cat_x < 0:
cat_x = 280
if cat_y > 220:
cat_y = 0
if cat_y < 0:
cat_y = 220
DISPLAYSURF.blit(cat_img, (cat_x, cat_y))
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
pfs_clock.tick(FPS)Vielen Dank im Voraus.
Grüße JohannesGolf