python - 我写了一个 pygame 程序,但是当我尝试使用 py2exe 时,我在 dist 中没有得到 exe

标签 python pygame exe py2exe

我编写了一个名为 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。

最佳答案

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

关于python - 我写了一个 pygame 程序,但是当我尝试使用 py2exe 时,我在 dist 中没有得到 exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10938242/

相关文章:

python - 网页字数统计

python - 为什么从包中全局安装 Django 不起作用? (通过python调用)

python - 为什么我在 pygame 中得到的是正方形而不是圆形?

matlab - 命令行不会等到 exe 执行完成

Java 存储配置和其他文件

python - 如何在 Python 中捕获对列表项的直接引用以提高速度?

python - 无法在 ubuntu 上安装 lxml

python-3.x - Pygame 错误地渲染等距图像

python - 在蛇游戏中增加蛇的长度

java - 如何将exe文件转换为.jar文件?