Python Turtle Graphics 作为 exe?

问题描述 投票:0回答:1

我用 pyinstaller 创建了 exe 文件,但它只显示控制台几毫秒。还有什么方法可以打开 Python Turtle Graphics 吗?我尝试用 python 海龟图形制作小游戏,它可以在箭头键上运行。(抱歉语法或解释不好,我对编程有点陌生)这是我的一些代码:

import turtle
import time
import math
import threading
import random
import pygame

pygame.init()
pygame.mixer.init()
pygame.mixer_music.load("Red Sun.mp3")
pygame.mixer_music.play(-1)
pygame.mixer_music.set_volume(.7)

ekran = turtle.Screen()
ekran.setup(800, 700)
ekran.cv._rootwindow.resizable(False, False)
turtle_mozna_ruszac = True
turtle.fillcolor("red")
turtle.pencolor("white")
turtle.shapesize(2)
turtle.shape("square")
enemy = turtle.Turtle()
enemy.shape("circle")

...

def obroc(deg):
    turtle.speed(11)
    turtle.setheading(deg)
    turtle.speed(4)

def ruch(deg, distance):

    global turtle_mozna_ruszac
    if not turtle_mozna_ruszac:
        return


    new_x = turtle.xcor() + distance * math.cos(math.radians(deg))

    if -300 <= new_x <= 300:
        turtle_mozna_ruszac = False
        obroc(deg)
        turtle.forward(distance)
        print(turtle.pos())
        turtle_mozna_ruszac = True

...

turtle.onkey(lewo, 'Left')
turtle.onkey(prawo, 'Right')

...

turtle.listen()
ekran.mainloop()
turtle.exitonclick()

我尝试在here执行此代码,但它对我不起作用

python pyinstaller exe turtle-graphics python-turtle
1个回答
0
投票

以扩展名 .pyw 保存,然后使用 pyinstaller 将其转换为可执行文件。

© www.soinside.com 2019 - 2024. All rights reserved.