Turtle window not closing

2017-04-21 Thread Harshika Varadhan via Python-list
Hi everyone,
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. 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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Turtle window not closing

2017-04-22 Thread Harshika Varadhan via Python-list
Thank you for your response. I apologize for that, this is my first time 
posting so I wasn't sure how to copy my code! 
I figured out that using the clear() method works for clearing the turtle 
window after drawing the game board, but now I am trying to figure out how to 
make the program wait a few seconds or wait for the user to press a key before 
clearing the turtle window (not closing the window, just clearing it). Is there 
any way to do this?

def draw_board():
t = turtle.Turtle()
t.speed(0)
t.ht()
t.up()
t.goto(-100, -100)
t.down()

for i in range(7, -1, -1):
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)
else:
if j != 7:
for l in range(4):
t.forward(50)
t.left(90)
t.forward(50)
if j == 7:
for l 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)
wn.clear()
I appreciate your help.
Thanks,
Harshi


On Saturday, April 22, 2017 3:56 AM, Peter Otten <[email protected]> wrote:



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. 


-- 

https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list