Python Turtle Window with Scroll Bars

I am new to Python and wrote a simple program in Python 2.7 using turtles graphics that draws a fractal shape. The problem is that there are no scroll bars in the turtle window, so if the shape is too large for the window, it is impossible to see it. Googled, but did not find the answer. Can anyone help?

+4
source share
2 answers

Finally, I found the code http://www.python-forum.de/viewtopic.php?f=1&t=24823&start=0 , which contains a scroll 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() 
+2
source

You do not need to directly access the Tkinter functions to get scrollbars in turtle . You just need to call turtle.screensize and set the screen size to be larger than the display window in at least one of its sizes. It’s more convenient for me to open the default display window, and if necessary, the user can change its size.

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() 
+2
source

All Articles