`turtle` and Flask hybrid not working

Hello, coding Replers,

So during the day, I had a very cool idea of a workaround for image drawing with PHP ( since I didn’t have the knowledge of it ) and it is joining the good ol’ friens turtle and Flask! I thought this would be a very cool and easy project, but when I ran the idea, no errors! It only showed a VNC container with a blank computer and the secondary tabs being only the console, but when I tried to visit https://turtle.rixthetyrunt.repl.co/progress/?height=1&percent=100 it should show me a small progress bar-like thing, but guess what? A blue-black screen with blue binoculars… You can guess it, it’s the old friend “Hmm… We couldn’t reach this Repl” screen! So, why is it like that and making me not show a progress bar no matter what? Take some code:

EDIT: It isn’t creating any Postscript files nor .PNG images too :grimacing:

Repl link: turtle - Nix (beta) Repl - Replit

from turtle import *
from flask import *
from PIL import Image
app = Flask("turtle")
sc = Screen()
sc.getcanvas().winfo_toplevel().withdraw()

@app.route("/progress/")
def progressBar():
	t = Turtle()
	t.speed(0)
	try:
		sc.screensize(int(request.args["height"]) + 2, 102)
	except:
		if not "height" in request.args or not request.args["height"].isdigit():
			abort(400)
	sc.bgcolor("Black")
	t.color("White")
	t.penup()
	t.goto(1, 1)
	t.pendown()
	t.goto(101, 1)
	t.goto(1, 1)
	t.color("#42d46d")
	try:
		t.goto(int(request.args["percent"]))
	except:
		if not "percent" in request.args or not request.args["percent"].isdigit():
			abort(400)
	t.getscreen().getcanvas().postscript(file="temp.ps")
	Image.open("temp.ps").save("temp", "png")
	return send_from_directory(".", "temp.png")

app.run(host="0.0.0.0", port=8080)

Hi @RixTheTyrunt I wouldn’t use turtle here, as it has trouble with threading. Instead, just use PIL. I made an example here: loader - Python Repl - Replit, https://loader.codingcactus.repl.co/progress/?height=10&percent=10

@CodingCactus It still shows it…

@RixTheTyrunt “it still shows it” what are these "it"s referring to?

Try to open that link in the question, not working… :c

@RixTheTyrunt yes I’m aware… That is why I sent a link to a repl showing an alternative way to achieve what you want.

I’m gonna delete my repl and create a new one with the exact same name

EDIT: Nevermind, now the repl works :sunglasses:

Hi @RixTheTyrunt so by recreating the Repl and copying the code in exactly as it was before, the error was solved?

Nah, they switched from using turtle to using PIL as I suggested. Turtle has problems with threading and also I don’t think you can run VNC and a webserver at the same time in Replit.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.