简体   繁体   English

如何在python乌龟模块中使画布更大

[英]How to make canvas bigger in the python turtle module

I made a turtle drawing program in python, but my canvas in which the turtle draws is not big enough.我用python做了一个画乌龟的程序,但是我画乌龟的画布不够大。 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.我正在trinket.io 中对此进行编程。

I am programming this in trinket.io.我正在trinket.io 中对此进行编程。

That is your problem -- Unfortunately, this is not possible in trinket.io.那是你的问题——不幸的是,这在trinket.io 中是不可能的。

Trinket.io does not support all the turtle methods. Trinket.io 不支持所有的turtle方法。 You can read which ones are supported here ;您可以在此处阅读支持哪些功能; I assume the rest are unsupported.我认为其余的不受支持。

This will work on your local python interpreter:这将适用于您的本地 python 解释器:

import turtle

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

But this will fail in Trinket.io, with a message like:但这将在 Trinket.io 中失败,并显示如下消息:

> 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.该文档暗示支持turtle.setup() ,但是,它似乎不支持,因为这将在您的本地python 解释器上运行并在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:我在 trinket.io 中唯一能做的就是能够通过以下方式返回(未设置)尺寸:

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

It looks like you can use:看起来你可以使用:

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)

Here is my trinket :-)这是我的小饰品:-)

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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