I am making a website with flask framework as a simple project, and I'm wondering if there is a way to embed a python turtle script, I know I can use the jinja {% python stuff %}{% end python stuff %}
for simple python statements but I don't know how to run a script.
To be even more specific, I want to run a python turtle game I made, so I need to somehow embed the turtle window and make it "listen" for user input until you press certain keys, like the esc or p key for example.
Say I want to embed this simple turtle game:
import turtle
#screen
wn = turtle.Screen()
wn.setup(width = 600,height = 600)
wn.title("Turtle Game")
#player
player = turtle.Turtle()
player.shape("turtle")
player.color("green")
player.up()
player.speed(0)
player.setposition(0,0)
#controls
def go_forw():
player.forward(10)
def go_back():
player.forward(-10)
def turn_r():
player.right(5)
def turn_l():
player.left(5)
#key input & loop
turtle.listen()
turtle.onkey(go_forw,'Up')
turtle.onkey(go_back,'Down')
turtle.onkey(turn_l,'Left')
turtle.onkey(turn_r,'Right')
turtle.mainloop()
I know it can be done using replit, but replit doesn't support some modules I want to use, is it possible to embed a turtle script like this one without hosting your code somewhere online?
I will be glad for any answer.
Thanks in advance.