Something is wrong. Turtle’s screen method "onkey" doesn’t work after I used another method – "textinput". Do you have any suggestions?
screen.onkey(snaky.up,'w') #key listening "
screen.onkey(snaky.down,'s')
screen.onkey(snaky.left,'a')
screen.onkey(snaky.right,'d')
for bodypart in snaky.segments[1:]:
if snaky.head.distance(bodypart)<10:
#game_is_on=False
answer=screen.textinput('RESTART','Do you want to re4start the game?')
if answer.lower()==('yes')
snaky.reset()
fruit.new_position()
score.reset_2()
if answer.lower()==('no'):
game_is_on=False
break`
>Solution :
after using method -‘textinput’ your programm started ignoring interactions with keyboard,so you have to use another method called -‘listen()’.
i can show you how u can use it specially in your programm:
when we use if,wich determines that the answer is yes,before updating the snake and so on.write – screen.listen()
answer=screen.textinput('RESTART','Do you want to re4start the game?')
if answer.lower()==('yes')
screen.listen
snaky.reset()
fruit.new_position()
score.reset_2()
if answer.lower()==('no'):
game_is_on=False
break`
this method makes it possible to interact with the keyboard again!