Potentially Using Anvil for Putting a Turtle Game on the Web

Hello!

I’m sort of newer to Anvil. I’ve built a game that essentially consists of five to six Python files and four music files in PyCharm. I’ve imported a couple of objects from the turtle module and also a pygame module for the music. Ultimately, I just want to get this on the web for it to be available to play there. I don’t know if that’s possible in general, including with a tool like Anvil. I envision maybe having some URL which people use, and, when the page loads, essentially the same game screen will pop up for them that I see when I run my game/project in PyCharm, but, for them, it will be in a web browser.

I’ve explored around to a degree in Anvil and at least started building like a simple form app. I’m not sure if what I’m describing is possible to do with Anvil (or possible at all).

Does anyone know if something like this is possible?

Thanks!

How the UI is managed in your script is very likely different from what you need in Anvil.

How do you update the UI in your script?

you might be able to embed something like this:

…into an html page as an anvil component.

I have no clue how though, but it exists, and I think it even uses skulpt, like anvil uses to turn python into javascript.

Skulpt (the underlying architecture beneath Anvil that makes it possible for python to be executable on browser) does contain Turtle module (in fact, it is the first example you’ll see on their website).

But surprisingly, when you try to import turtle module in client side python, you see this error

image

Not sure why it happens. But seeing the great support for the turtle module in Skulpt, it sounds like something that can definitely be done with Anvil.

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.

Hi, Stefano! I’m still kind of learning the ropes with quite a bit of computer programming stuff. When you say, “script,” are you referring to like any JavaScript code I have in my game? Thanks!

Thank-you so much! I think I tried using Trinket, but I don’t know if it will also allow me to import anything from pygame. It might also not let me use multiple Python files.

Thank-you very much! I don’t know if I’ve used Skulpt directly, yet. I appreciate your feedback, and I may look into Skulpt more and maybe more into Anvil maybe once I have a better understanding of the capabilities of Skulpt.

Thanks a lot! I appreciate the feedback! When you say, “toy apps,” are you referring to like simple turtle apps, using like one file?

Your best bet is probably trinket or repl.it. Both have pygame support, which anvil doesn’t.

1 Like

Thank-you! Hopefully I’ll find a solution to get the game on the web!