Whenever I try and run my program, it draws the two turtles and then the window stops responding.
What I was expecting is that, until one of the pieces touches the other one based on me dragging it close to the other one, I will be able to drag both of them by themselves. What's happening though is that whenever I run the program, after drawing both of the turtles, the window stops responding. I don't get any errors, it just closes after freezing until I click the close button. I've looked at other people's post where they had this problem but they haven't had screen.mainloop() at the end and I do.
import turtle
captured_pieces = []
blue = turtle.Turtle()
black = turtle.Turtle()
screen = turtle.Screen()
blue.penup()
black.penup()
blue.shape('square')
black.shape('triangle')
blue.setpos(100,100)
black.setpos(-100,-100)
blue.color('blue')
black.color('black')
def bmove():
black.ondrag(black.goto)
if black.distance(blue) < 30:
captured_pieces.append("BlC")
print(captured_pieces)
check()
def blmove():
blue.ondrag(blue.goto)
if blue.distance(black) < 30:
captured_pieces.append("BC")
print(captured_pieces)
check()
def check():
if "BlC" in captured_pieces:
print("blue captured")
def check():
if "BC" in captured_pieces:
print("black captured")
while "BlC" not in captured_pieces and "BC" not in captured_pieces:
bmove()
blmove()
screen.mainloop()