How to make canvas bigger in turtles python

杀马特。学长 韩版系。学妹 提交于 2019-12-08 11:09:12

问题


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)


来源:https://stackoverflow.com/questions/32898883/how-to-make-canvas-bigger-in-turtles-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!