【问题标题】:I wrote a pygame program but when I try to use py2exe I don't get an exe in the dist我写了一个 pygame 程序,但是当我尝试使用 py2exe 时,我没有在 dist 中得到一个 exe
【发布时间】:2012-06-07 19:04:25
【问题描述】:

我编写了一个名为 Hello.py 的程序,如下所示:

import pygame, sys
from pygame.locals import *

# set up pygame
pygame.init()

# set up the window
windowSurface = pygame.display.set_mode((500, 400), 0, 32)
pygame.display.set_caption('Hello world!')

# set up the colors
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

# set up fonts
basicFont = pygame.font.SysFont(None, 48)

# set up the text
text = basicFont.render('Hello world!', True, WHITE, BLUE)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery

# draw the white background onto the surface
windowSurface.fill(WHITE)

# draw a green polygon onto the surface
pygame.draw.polygon(windowSurface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))

# draw some blue lines onto the surface
pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120))
pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4)

# draw a blue circle onto the surface
pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)

# draw a red ellipse onto the surface
pygame.draw.ellipse(windowSurface, RED, (300, 250, 40, 80), 1)

# draw the text's background rectangle onto the surface
pygame.draw.rect(windowSurface, RED, (textRect.left - 20, textRect.top - 20, textRect.width + 40, textRect.height + 40))

# get a pixel array of the surface
pixArray = pygame.PixelArray(windowSurface)
pixArray[480][380] = BLACK
del pixArray

# draw the text onto the surface
windowSurface.blit(text, textRect)

# draw the window onto the screen
pygame.display.update()

# run the game loop
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

我有一个名为 setup.py 的程序,它看起来像这样:

from distutils.core import setup
import py2exe
import pygame

setup(window=['Hello.py'])

当我运行 py2exe 时,它​​会创建一个 dist 文件夹,但文件夹内没有 exe 文件,只有它创建的其他文件。我讨厌一直问这样的问题,但我的时间有点短,没有时间用我的电脑播放 20 条错误消息。我目前正在运行 windows vista。

【问题讨论】:

  • 看到这个similar question
  • 另外setup 中的选项应该是windows 而不是window

标签: python pygame exe py2exe


【解决方案1】:

Pygame 已经有一个使用 pygame 和 py2exe 的默认程序,Pygame2exe。 这是一个link。 只需在 BuildExe.__init__ 中填写参数并运行它。您甚至不必在控制台中运行它,因为它会将“py2exe”添加到参数中。 希望这个答案有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-20
    • 2015-04-29
    • 1970-01-01
    • 2011-02-09
    • 2011-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多