Ask coding questions

← Back to all posts
Help
AmiteshJinka (1)

Can someone please tell me how to disable .onkey() in python turtle? I have to make in a way so that once one of the turtles hits the other, the second turtle dies. Every time the first turtle hits the second, the player can still move around. I want to know how to stop that from happening. Please help me.

Comments
hotnewtop
[deleted]

gimme the repl

[EDIT]: I found the repl

AmiteshJinka (1)

@Aphmeta Don't worry, I have figured it out. (Ignore everything else but the 'draw' game)

AmiteshJinka (1)

@Aphmeta All good. I figured it out. (Ignore everything but the 'draw' game. This was a past project that I'm trying to improve on).

SixBeeps (5331)

Instead of "disabling" the onkey, you can set a flag that will make the attached function stop before it moves anything. Kinda like this:

def moveme():
  if (iAmDead):
    return
  turt.left(69)

scene.onkey(moveme, "Left")

Then you can set iAmDead to True to prevent the turtle from moving.

AmiteshJinka (1)

@SixBeeps Thanks! I figured it out