5

I am new to Python, and have written a simple program in Python 2.7 using turtle graphics, which draws a fractal shape. The problem I have is that the turtle window doesn't have scrollbars, so if the shape is too large for the window, it is impossible to see all of it. Have googled but found no answer. Can anyone help?

cdlane
  • 40,441
  • 5
  • 32
  • 81
nixey26
  • 91
  • 1
  • 4
  • It [appears to be possible](http://docs.python.org/2/library/turtle.html#turtle.ScrolledCanvas) to add scrollbars, but it requires some knowledge of Tkinter. – Kevin Feb 06 '13 at 14:04

2 Answers2

5

You don't need to call Tkinter functions directly to get scrollbars in turtle. You just need to call turtle.screensize and set a screen size that's larger than the display window in at least one of its dimensions. I find it most convenient to open the display window at its default size and let the user resize it, if desired.

Here's a short demo:

import turtle

win_width, win_height, bg_color = 2000, 2000, 'black'

turtle.setup()
turtle.screensize(win_width, win_height, bg_color)

t = turtle.Turtle()
#t.hideturtle()
#t.speed(0)
t.color('white')

for _ in range(4):
    t.forward(500)
    t.right(90)

turtle.done()
PM 2Ring
  • 54,345
  • 6
  • 82
  • 182
4

Finally found some code at http://www.python-forum.de/viewtopic.php?f=1&t=24823&start=0 which provides a scrolled canvas for the turtle:

import turtle
import Tkinter as tkinter

root = tkinter.Tk()
root.geometry('500x500-5+40') #added by me
cv = turtle.ScrolledCanvas(root, width=900, height=900)
cv.pack()

screen = turtle.TurtleScreen(cv)
screen.screensize(2000,1500) #added by me
t = turtle.RawTurtle(screen)
t.hideturtle()
t.circle(100)

root.mainloop()
hola
  • 930
  • 1
  • 17
  • 35
nixey26
  • 91
  • 1
  • 4