Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Something is wrong. Turtle's screen method "onkey" doesn't work after I used another method – "textinput". Do you have any suggestions?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading