Search code examples
pythonpyinstallerexeturtle-graphicspython-turtle

Python Turtle Graphics as exe?


I created exe file with pyinstaller, but it only shows console for couple milliseconds.Any way to open Python Turtle Graphics as well? I tried to make small game in python turtle graphics, it works on arrow keys.(Sorry for bad grammar or bad explanation, I'm kinda new to programimg) Here is some of my code:

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()

I tried doing this code here, but it didn't worked for me


Solution

  • Save it with extension .pyw then use pyinstaller to convert it to executable.