I'm trying to make a pygame file executable with py2exe (I have Python 2.7). The program is composed of 3 scripts.
I wrote the setup as:
from distutils.core import setup
import py2exe
setup(console=["main.py"])
From the command window, I ran the setup:
setup.py py2exe
and I got my program .exe in the dist folder. The problem is, when I run it, a black window opens and immediately closes.
Now, I know that this is normal if the program does not wait for any input, but in my program there is a while loop that should go on until the user closes the game window. I also tried to put at the beginning of the program a raw_input but it changes nothing.
Then I tried to create a very simple file to test:
a = raw_input("hello")
print(a)
I converted it to .exe and it works. So, I guess that the problem is in my pygame file. Here is the code of the main (functions and classes are the other 2 scripts of the game):
import pygame, sys, functions
from classes import *
pygame.init()
pygame.font.init()
display_width = 600
display_height = 600
screen = pygame.display.set_mode((display_width,display_height))
menuImage = pygame.image.load("images/menu_t.jpg")
# colors
backgroundColor = (255,255,102)
buttonColor = (153,76,0)
buttonColorBright = (204,102,0)
# create tiles
for y in range(0,screen.get_height(),Tile.WIDTH):
for x in range(0,screen.get_width(),Tile.HEIGHT):
Tile(x,y)
# starting menu
while True:
screen.blit(menuImage,(0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYUP:
if event.key == pygame.K_ESCAPE:
pygame.quit()
sys.exit()
functions.button(screen,"Play",display_width/2-50,display_height/2,100,50,buttonColor,buttonColorBright,"play_game")
functions.button(screen,"Quit",display_width/2-50,display_height/2+75,100,50,buttonColor,buttonColorBright,"quit")
pygame.display.flip()
This is the main, it should load a background image and 2 buttons. What could be the reason the executable program doesn't work properly?