Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14126

Using tracer delays the eventlistener response in turtle library, python

$
0
0

so I am trying to create a snake game using the turtle GUI library in python. However when I am using the tracer function of the turtle library and screen class for the smooth animations, my eventlistener's(keyboard inputs) response are appearing a lot delayed. Whenever I turn the tracer off, eventlistener's response again are immediate. Can anyone help me and explain why this is happening also what can I do for the immediate keyboard input to be appropriately dealt with on the screen. Thanks in advance! Here is the program for your reference.

import turtlefrom snake import Snakeimport timeturtle.mode("standard")window = turtle.Screen()window.setup(width=600, height=600)window.bgcolor("black")window.title("Snake game")window.tracer(n=0)window.listen()snake = Snake()window.onkey(fun=snake.goup, key="Up")window.onkey(fun=snake.godown, key="Down")window.onkey(fun=snake.goleft, key="Left")window.onkey(fun=snake.goright, key="Right")window.onkey(fun=snake.goup, key="w")window.onkey(fun=snake.godown, key="s")window.onkey(fun=snake.goleft, key="a")window.onkey(fun=snake.goright, key="d")game_is_on = Truewhile game_is_on:    window.update()    time.sleep(1)    snake.move()    window.update()window.exitonclick()

Viewing all articles
Browse latest Browse all 14126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>