I'm learning pygame on my mac and I have:
- python 3.6.1
- pygame 1.9.3
I just followed a tutorial and tried to create a simple window. But what I found was that after I ran it on the terminal, nothing happened. No window popped out, no error.
I've searched for some solutions and found that using
pythonw test.py
could solve my problem,
but I tried it and still failed.
What's strange was that this worked on other pygame codes that I found on the net.
So here's my code, it would be great if somebody can help me with this problem. I've been searching for the solution for half day. Thanks!
import pygame
display_width = 800
display_height = 600
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
green = (0,255,0)
blue = (0,0,255)
pygame.init()
gameDisplay = pygame.display.set_mode((display_width,display_height))
pygame.display.set_caption('Bballing')
clock = pygame.time.clock()
ballImg = pygame.image.load('bball.png')
def ball(x,y):
gameDisplay.blit(ballImg, (x,y))
def game_loop():
x = (display_width * 0.45)
y = (display_height * 0.8)
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -5
elif event.key == pygame.K_RIGHT:
x_change = 5
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_change = 0
x += x_change
gameDisplay.fill(white)
ball(x,y)
pygame.display.update()
clock.tick(60)
game_loop()
pygame.quit()
quit()