Make the Python Turtle screen self adjust to show what's been drawn?
<p>I've been trying to find an answer to this all over the internet, and just can't find anything that works. </p>

<p>Essentially, I'm building my very first program which is a <code>digital spirograph</code>. One of the features of this is that you can have the turtle randomly draw a shape using fairly chaotic variables. </p>

<p>My issue is that when I do this, the turtle almost always draws out of the borders of the turtle window, therefore not allowing the user to see the full completed drawing at the end.</p>

<ul>
<li>Is there an easy way to have the screen resize to the bounds of what has been drawn after the turtle finishes? </li>
</ul>

<p>I'm not sure if I should list my code as it's a few hundred lines long at this point, but if that is needed let me know. </p>

<p>Edit: Here is my code as it currently is written -</p>

<pre><code>import turtle
import random

print("Random Mode? y/n")
crazy = raw_input()
crazy = str(crazy)
if crazy == 'y' :
    print("Would you like your random selection to be chaotic? y/n")
    chaos = raw_input()
    chaos = str(chaos)
    if chaos == 'y' :
        passes_r = random.randint(4,15)
        angle_r1 = random.randint(1,180)
        angle_r2 = random.randint(1,180)
        angle_r3 = random.randint(1,180)
        angle_r4 = random.randint(1,180)
        angle_r5 = random.randint(1,180)
        angle_r6 = random.randint(1,180)
        angle_r7 = random.randint(1,180)
        angle_r8 = random.randint(1,180)
        chaos_r1 = random.randint(0,360)
        chaos_r2 = random.randint(0,360)
        chaos_r3 = random.randint(0,360)
        chaos_r4 = random.randint(0,360)
        chaos_r5 = random.randint(0,360)
        chaos_r6 = random.randint(0,360)
        chaos_r7 = random.randint(0,360)
        chaos_r8 = random.randint(0,360)


        shape_r = ['arrow', 'turtle', 'circle', 'square', 'triangle',     'classic']
        turtle.shape(random.choice(shape_r))
        turtle.speed(0)

        print("Calculating shape based on random input: ") + str(angle_r1) + ", " + str(angle_r2) + ", " + str(angle_r3) + ", " + str(angle_r4) + ", " + str(angle_r5) + ", " + str(angle_r6) + ", " + str(angle_r7) + ", " + str(angle_r8)

        for _ in range(passes_r):

            turtle.color('red')
            turtle.left(angle_r1)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r1)

            turtle.color('blue')
            turtle.left(angle_r2)

            for _ in range(4):
                    turtle.forward(100)
                    turtle.left(chaos_r2)

            turtle.color('green')
            turtle.left(angle_r3)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r3)

            turtle.color('yellow')
            turtle.left(angle_r4)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r4)

            turtle.left(angle_r5)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r5)

            turtle.color('green')
            turtle.left(angle_r6)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r6)

            turtle.color('blue')
            turtle.left(angle_r7)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r7)

            turtle.color('red')
            turtle.left(angle_r8)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(chaos_r8)




    elif chaos == 'n' :
        passes_r = random.randint(4,15)
        angle_r1 = random.randint(1,180)
        angle_r2 = random.randint(1,180)
        angle_r3 = random.randint(1,180)
        angle_r4 = random.randint(1,180)
        angle_r5 = random.randint(1,180)
        angle_r6 = random.randint(1,180)
        angle_r7 = random.randint(1,180)
        angle_r8 = random.randint(1,180)

        shape_r = ['arrow', 'turtle', 'circle', 'square', 'triangle', 'classic']
        turtle.shape(random.choice(shape_r))
        turtle.speed(0)

        print("Calculating shape based on random input: ") + str(angle_r1) + ", " + str(angle_r2) + ", " + str(angle_r3) + ", " + str(angle_r4) + ", " + str(angle_r5) + ", " + str(angle_r6) + ", " + str(angle_r7) + ", " + str(angle_r8)

        for _ in range(passes_r):

            turtle.color('red')
            turtle.left(angle_r1)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.color('blue')
            turtle.left(angle_r2)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.color('green')
            turtle.left(angle_r3)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.color('yellow')
            turtle.left(angle_r4)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.left(angle_r5)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.color('green')
            turtle.left(angle_r6)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.color('blue')
            turtle.left(angle_r7)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)

            turtle.color('red')
            turtle.left(angle_r8)

            for _ in range(4):
                turtle.forward(100)
                turtle.left(90)


elif crazy == 'n' :

    print("Enter number of repeats -")
    passes = raw_input() # passes is called in line 23 for range
    passes = int(passes)

    print("Enter Shape: Arrow, Turtle, Circle, Square, Triangle, or Classic")
    shape = raw_input().lower() # Selects the shape of the turtle

    print("Enter Speed: (# 0 through 10: 0 is the fastest)")
    user_speed = raw_input()
    user_speed = int(user_speed)

    print("Enter Angle 1 (# between 1 and 180)")
    angle_1 = raw_input()
    angle_1 = int(angle_1)

    print("Enter Angle 2 (# between 1 and 180)")
    angle_2 = raw_input()
    angle_2 = int(angle_2)

    print("Enter Angle 3 (# between 1 and 180)")
    angle_3 = raw_input()
    angle_3 = int(angle_3)

    print("Enter Angle 4 (# between 1 and 180)")
    angle_4 = raw_input()
    angle_4 = int(angle_4)

    print("Enter Angle 5 (# between 1 and 180)")
    angle_5 = raw_input()
    angle_5 = int(angle_5)

    print("Enter Angle 6 (# between 1 and 180)")
    angle_6 = raw_input()
    angle_6 = int(angle_6)

    print("Enter Angle 7 (# between 1 and 180)")
    angle_7 = raw_input()
    angle_7 = int(angle_7)

    print("Enter Angle 8 (# between 1 and 180)")
    angle_8 = raw_input()
    angle_8 = int(angle_8)

    print("Auto size y or n?")
    auto_size = raw_input().lower()
    auto_size = str(auto_size)
    if auto_size == 'y' :
        auto_size = str('auto')
        turtle.resizemode(auto_size)
    elif auto_size == 'n' :
        auto_size = str('noresize')
        print("what size? Enter a number from 1 to 10.")
        user_size = raw_input()
        user_size = int(user_size)
        turtle.pensize(user_size)




    turtle.shape(shape)
    turtle.speed(user_speed)
    #turtle.resizemode(auto_size)

    print("Calculating shape based on user input: ") + str(angle_1) + ", " + str(angle_2) + ", " + str(angle_3) + ", " + str(angle_4) + ", " + str(angle_5) + ", " + str(angle_6) + ", " + str(angle_7) + ", " + str(angle_8)

    for _ in range(passes):

        turtle.color('red')
        turtle.left(angle_1)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.color('blue')
        turtle.left(angle_2)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.color('green')
        turtle.left(angle_3)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.color('yellow')
        turtle.left(angle_4)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.left(angle_5)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.color('green')
        turtle.left(angle_6)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.color('blue')
        turtle.left(angle_7)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)

        turtle.color('red')
        turtle.left(angle_8)

        for _ in range(4):
            turtle.forward(100)
            turtle.left(90)


turtle.exitonclick()
</code></pre>

<p>resize the window using the following code in python</p>

<p>By the way your question is duplicated I think.</p>

<p><a href="http://stackoverflow.com/questions/831894/python-imaging-resize-turtle-graphics-window">Python imaging, resize Turtle Graphics window</a></p>

<pre><code>setup( width = 200, height = 200, startx = None, starty = None)  
</code></pre>

python