What I’m trying to do: Connect python turtle library to HTML element
What I’ve tried and what’s not working: creating a div with a canvas inside in HTML,
Code Sample:
#imports
from anvil.js import window
class Form2(Form2Template):
def init (self, **properties):
super().init (**properties)
def form_show(self, **event_args):
import turtle
window.Sk.canvas = “turtle”
see this post which is probably the most relevant
To make Skulpt work with the turtle module it looks for a container of a canvas whose id is “turtle”
Create a CustomComponent and use the html:
<div id="turtle"><canvas width=400 height=400></canvas></div>
But it’s not something we’d recommend implementing apart from toy apps.
Typically if you wanted to use Skulpt to work with turtle, you’d be doing this directly with Skulpt, rather than with Anvil.
I’ve done exactly that: created a customComponnent, but its still not working, and I can’t figure out why. I’m using turtle because it’s what I’m used to and it’s the best for the project I’m doing, but like I said I can’t get it to show in the app.
In that case, it’s probably best to share a clone link so others can see and run your code themselves.
Some instructions here:
Welcome to the Q&A Forum!
Help each other by asking questions about Anvil, and answering other people’s.
Post each question as a new topic - and if someone helps you, don’t forget to say thank-you. Try to provide information to help people answer your questions:
Be specific about what you’re trying to do.
Be specific about what your problem is (eg what’s not working), and what you have already tried.
Include code samples if you can.
It often helps if you can share your app’s source code and …
Have you tried adding print debug statements? To make sure your form_show event handler is running.
Are you seeing any errors?
Sorry to waste your time but I actually got it working I hadn’t added the handler to tell the form that the form had been showed the trigger form_show but thanks for the feedback anyway.
1 Like