Turtle window not closing

Peter Otten __peter__ at web.de
Sat Apr 22 03:52:56 EDT 2017


Harshika Varadhan via Python-list wrote:

> I am creating a game where the user inputs a coordinate to place their
> piece on a chess board. My code then draws the chess board with a turtle
> and fills in the squares in with green where the user can place their next
> piece. After the user inputs their first coordinate, the turtle draws the
> board, but then the window doesn't close and the program ends up crashing.

It probably raises an exception and prints a traceback. That "traceback" 
contains the location and a description of the error Python encountered in 
your script and is therefore valuable information that can help you fix your 
code. If you get a traceback always include it into your mail (use cut-and-
paste).

> Is there any way to solve this problem?I appreciate your help. My function
> for drawing the chess board: def draw_board():    t = turtle.Turtle()   
> t.speed(0)    t.ht()    t.up()    t.goto(-100, -100)    t.down() for i in
> range(0, 8):        for j in range(0, 8):            if free_squares[i][j]
> == ".":                if j != 7:                    t.fillcolor("green") 
>                   t.pencolor("black")                    t.begin_fill()   
>                 for k in range(4):                        t.forward(50)   
>                     t.left(90)                    t.end_fill()            
>        t.forward(50)                if j == 7:                   
> t.fillcolor("green")                    t.pencolor("black")               
>     t.begin_fill()                    for k in range(4):                  
>      t.forward(50)                        t.left(90)                   
> t.end_fill()                    t.right(270)                   
> t.forward(50)                    t.left(90)                   
> t.forward(350)                    t.right(180) turtle.bye() Thank you,
> Harshi

That's pretty unreadable. Please remember to post plain text with line-
wrapping turned off next time.

> the program ends up crashing.

If I were to guess: Did you define the `free_squares` list of lists 
properly?

> but then the window doesn't close

Are you running your script from within IDLE? Try starting it from the 
command line instead.

Like turtle IDLE itself is a program written in tkinter, and the separation 
between editer and user code is not always perfect. 




More information about the Python-list mailing list