game.py:
import pygame
pygame.init()
if pygame.get_init():
print("pygame successfully initialized")
else:
print("pygame failed to initialize")
background_color = (255,0,0)
(width, height) = (800, 800)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Game')
x = int(width / 2)
y = int(height / 2)
speed = 10
running = True
while running:
screen.fill(background_color)
# drawing
pygame.draw.circle(screen, (0,0,255), (x, y), 50)
#input
keys = pygame.key.get_pressed()
if keys[97]:
x -= speed
elif keys[100]:
x += speed
if keys[119]:
y -= speed
elif keys[115]:
y += speed
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
setup.py:
from cx_Freeze import setup, Executable
includefiles = ['PNG']
includes = []
excludes = []
packages = []
setup(
name = 'game',
version = '0.1',
description = 'IDk',
options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable("game.py")]
)
When I run the setup.py script it makes an executable that does run, however, it just creates an empty pygame window. If I run the script with 'python game.py' in the terminal it works fine. I have seen many people who can't get pygame programs to run with cx_Freeze and the fix is to add import re
but that does not fix my problem. I also do not get any errors and the terminal pops up and says the usual 'welcome to pygame' message.