+ 2
GUI-Based Python code in Webpage
I have the following Python code: https://sololearn.com/compiler-playground/cI8u3i2b4z9V/?ref=app And I want to run it in a webpage. Do note that it uses GUI graphics. I tried and barely got Pyscript running, then looked into other ones, but the GUI graphics from turtle isn't supported in any of the JavaScript libraries for running Python which I found(Brython, Pyodide). Is it possible to implement the code in my webpage, and if it is, how so?
7 Respuestas
+ 2
Afnan Irtesum Chowdhury
Yes, you can run your code in web compiler using skulpt.
Here is a example of how can you use turtle in your webpage:
https://sololearn.com/compiler-playground/W4gB8gfenNFH/?ref=app
Skulpt doesn't support all python standard library modules and unfortunately colorsys isn't available in Skulpt's supported built-ins.
To solve the issue, you can manually re-implement colorsys functions in Python.
+ 1
Gulshan Mahawar I modified the code, but the canvas stays pitch black(empty), no changes happen
EDIT: Got it to work, but can't change the color(all stars are red). Need some help...
https://sololearn.com/compiler-playground/WYhf79dzRRiP/?ref=app
+ 1
Afnan Irtesum Chowdhury
Try this:
`print(h)
print(r,g,b)
`
I found that h is getting modified in the loop but r,g,b isn't changing. That's pretty weird.
0
Yeah I just can't change the color no matter what, RGB value is not changing.
0
Afnan Irtesum Chowdhury
I used another way to try turtle on web and here it is-
https://sololearn.com/compiler-playground/WfSbMtX0Ov1S/?ref=app
But the problem I am getting is that when I try to put a bigger value in speed() (more than 10.4) it behaves like speed(0) and go too fast.
Edit: I fixed the issue, don't know you like it:-
Just replace for inner loop with this
`
for i in range(460):
rgb = hsv_to_rgb(h, 1, 0.8)
h += 1/n
pencolor(rgb_to_hex(rgb))
left(145)
for j in range(5):
speed(0)
forward(199)
speed(1)
forward(1)
left(150)
`
In this way we can slowed down the super fast turtle
0
Using Brython seems to take quite a lot of time to load the page, but thanks, since it fixed the issue. The speed is not a problem, we're not supposed to increase the speed over 10 anyways.
0
Now is the best time to start learning html5 canvas