简体   繁体   中英

Write() function of the Turtle graphics library doesn't work with Transcrypt

When I use the write() function of the Turtle graphics library in a Python script and then translate it in javascript with Transcrypt, it displays nothing.

My code looks like this:

import turtle

def SomeText():
    pen.goto(0, 250)
    pen.pensize(10)
    pen.write("Nothing happens")

pen = turtle.Turtle()
SomeText()
pen.done()

The program runs alright in a Python environment but it displays only the turtle line and no text when translated into Javascript through Transcrypt and then is executed on a web browser.

Am I doing something wrong or is it just that Transcrypt doesn't support the write() function? If this is the case, how can I combine the turtle graphics with text in a compact way into Javascript? It's not that convenient to use extra html code for text messages.

Your original code doesn't work for me. The line pen.done() isn't valid as done() isn't a method of turtle. It's an alias of the screen method mainloop() and is also available as a top level function that acts on the screen singleton instance.

I'm not saying it'll necessarily fix your stated problem, but to make your original code vaild, change pen.done() to turtle.done() . Ie change it from a non-existent turtle method call to a top level function call. Then try Transcrypt again...

After that, I'd consider the issue of fonts and do both Python and JavaScript have access to the default write() font Arial?

hm.... I don't know if I'm right, as I have left turtle quite a while ago, but aren't you supposed to add a lot more after just pen.write("nothing happens") ? For example: pen.write("something happens", True, 'center', font = ([whatever font], [whatever size], 'bold' [or not])) That may be the problem, but like I said before, I'm not too familiar with turtle and I've also never used Transcript or JavaScript.

Modify the Turtle graphics program to incorporate the functions of the left and middle mouse buttons. In other words, when you press the left mouse button, a random color changes and the size of the turtle changes, and a line is drawn.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM