I made a turtle drawing program in python, but my canvas in which the turtle draws is not big enough. I am trying to make this canvas bigger so that I can fit more on the page and make the stuff bigger. I am programming this in trinket.io.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I am programming this in trinket.io.
That is your problem -- Unfortunately, this is not possible in trinket.io.
Trinket.io does not support all the turtle
methods. You can read which ones are supported here; I assume the rest are unsupported.
This will work on your local python interpreter:
import turtle
print(turtle.Screen().screensize()) # returns (400,300) for me
But this will fail in Trinket.io, with a message like:
> AttributeError: 'Screen' object has no attribute 'screensize' on line 3 in main.py
The documentation implies that turtle.setup()
is supported, however, it seems not to be, because this will work on your local python interpreter and fail in trinket.io.
import turtle
turtle.setup(500,500)
The only thing I have been able to do in trinket.io is to be able to return (not set) the dimensions, via:
print(turtle.window_height())
print(turtle.window_width())
回答2:
import turtle
turtle.screensize(canvwidth=None, canvheight=None, bg=None)
tina = turtle.Turtle()
tina.shape('turtle')
your_name = input("What is your name")
tina.penup()
tina.forward(20)
tina.write("Why, hello there, " + your_name + "!", font=("Arial", 12, "normal"))
tina.backward(20)
tina.color("green")
tina.left(90)
tina.forward(100)
tina.right(90)
tina.goto(-65, 50)
tina.pendown()
tina.pencolor("red")
tina.forward(50)
tina.right(50)
tina.forward(50)
tina.right(100)
tina.forward(55)
tina.left(50)
tina.forward(55)
tina.penup()
tina.forward(30)
tina.pendown()
tina.dot(10)
tina.penup()
tina.goto(-100, 100)
color = input("What color is the question mark")
try:
if color == ("red"):
tina.write("Your are correct " + your_name + "!", font=("Arial", 20, "normal"))
tina.backward(20)
elif color == ("green" or "Green"):
tina.left(90)
tina.write("Sorry, It is actually Red", font=("Arial", 12, "normal"))
tina.forward(100)
elif color == ("black" or "Black"):
tina.write("Sorry, Its is actually Red", font=("Arial", 12, "normal"))
tina.backward(20)
elif color == ("purple" or "Purple"):
tina.write("Sorry, It is actually Red", font=("Arial", 12, "normal"))
tina.backward(20)
elif color == ("blue" or "Blue"):
tina.write("Sorry, It is actually Red", font=("Arial", 12, "normal"))
tina.backward(20)
except:
tina.backward(20)
tina.write("Sorry, but that isn't a color", font=("Arial", 12, "normal"))
tina.backward(20)