如何在海龟蟒蛇中制作更大的画布

时间:2015-10-02 00:40:17

标签: python size turtle-graphics

我在python中制作了一个乌龟绘图程序,但是乌龟绘制的画布不够大。我正在努力使这个画布更大,以便我可以在页面上更多地适应并使这些东西更大。我在trinket.io编程。

4 个答案:

答案 0 :(得分:2)

  

我正在trinket.io中对此进行编程。

那是你的问题-不幸的是,在trinket.io中是不可能的。

Trinket.io不支持所有的turtle方法。您可以阅读支持哪些here;我认为其余的都不支持。

这将在您的本地python解释器上工作:

import turtle

print(turtle.Screen().screensize()) # returns (400,300) for me

但这在Trinket.io中将失败,并显示如下消息:

> AttributeError: 'Screen' object has no attribute 'screensize' on line 3 in main.py

文档暗示支持turtle.setup(),但是似乎不支持,因为这将在您的本地python解释器上起作用,并且在trinket.io中失败。

import turtle

turtle.setup(500,500)

在trinket.io中,我唯一能做的就是能够通过以下方式返回(未设置)尺寸:

print(turtle.window_height())
print(turtle.window_width())

答案 1 :(得分:0)

您似乎可以使用:

import turtle

screen = turtle.Screen()
# this assures that the size of the screen will always be 400x400 ...
screen.setup(500, 500)
tina = turtle.Turtle()
tina.goto(200,200)
tina.goto(-200,-200)
tina.goto(-200,200)
tina.goto(200,-200)

这是我的trinket :-)

答案 2 :(得分:-1)

基本上,您可以通过turtle.screensize()函数控制画布大小:

turtle.screensize(canvwidth=None, canvheight=None, bg=None)

Where parameters: canvwidth = positive integer, new width of canvas in pixels canvheight = positive integer, new height of canvas in pixels bg = colorstring or color-tuple, new background color

您可以在海龟文档中找到更多信息:https://docs.python.org/2/library/turtle.html#turtle.screensize

但无论如何,对于更具体的答案,如果您要分享您正在处理的代码,那将非常简单。

编辑:

您缺少setup()功能,例如:

turtle.setup(800, 800) // sets window size by 800x800px

答案 3 :(得分:-1)

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)