Search code examples
pythonhtmlpython-turtlecode.org

How to add Python scripts to HTML


I have a python script which I want to display using HTML on code.org but I don't know what commands or methods I can use to display what I want shown. Here is an example of the HTML and the python script I want to run in it. (python code shortened for publishing)An example of the HTML

import turtle as fab
import pandas as pd

platform = [0.00151,0.00318,0.00436,0.00551,0.00563,0.00989,0.01196]

fab.speed(10)
fab.pensize(2.5)
fab.penup()
fab.right(90)
fab.forward(300)
fab.left(90)
fab.pendown() #sets the turtle in place at the bottom of the screen

fab.color('#49514c') #black colour for amazon
fab.begin_fill()
fab.circle(platform[6]*30000) # draws the circle for amazon music unlimited
fab.end_fill()

fab.penup()
fab.forward(450)
fab.left(90)
fab.forward(400)
fab.right(90)
fab.pendown() #moving the pen to write the text

fab.color('#49514c')
fab.write('Amazon Music Unlimited!', move=False, align="left", font=("Comic Sans", 20, "normal"))
fab.penup()
fab.right(90)
fab.forward(50)
fab.left(90)
fab.pendown() #write amazon

Solution

  • Short answer:

    You can't.

    Long answer:

    Python can't be run on a webpage, it's a backend language. You may want to use JavaScript and HTML Canvas objects to draw on them. You can use this as a starting point or google "JavaScript draw on canvas".

    Btw: To place the turtle at the bottom, you can use fab.goto(x, y) in Python