How to make canvas bigger in the python turtle module
Asked Answered
H

3

2

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.

Harmonic answered 2/10, 2015 at 0:40 Comment(0)
U
6

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())
Ugo answered 6/9, 2018 at 19:31 Comment(1)
I was able to set the screen size following the example here https://mcmap.net/q/1170625/-how-to-make-canvas-bigger-in-the-python-turtle-moduleParthenogenesis
P
1

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

Parthenogenesis answered 14/9, 2020 at 23:50 Comment(0)
H
-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)
Harmonic answered 2/10, 2015 at 1:7 Comment(1)
Is this an answer to your question, or is this your current code? If the latter, you should include this in your question, not in an answer post.Ventriloquy

© 2022 - 2024 — McMap. All rights reserved.