user5397689
user5397689

Reputation:

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. 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.

Upvotes: 2

Views: 25162

Answers (3)

David LeBauer
David LeBauer

Reputation: 31741

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 :-)

Upvotes: 1

C8H10N4O2
C8H10N4O2

Reputation: 19005

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())

Upvotes: 6

user5397689
user5397689

Reputation:

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)

Upvotes: -1

Related Questions