#Tkinter very laggy

20 messages · Page 1 of 1 (latest)

fallen pier
#

i would like some advice on how to make my tkinter game (for a school project) less laggy

edgy sparrow
#

You should share your code and explain what you mean by "laggy"

fallen pier
#

alright, give me a minute sorry

weary hamletBOT
#

@fallen pier

Ethan X Uploaded Some Code
Uploaded these files to a Gist
fallen pier
#

these are the images in "images"

#

i don't know how to link them sorry

#

but the issue is that (currently i only have movement of the ufo) the ufo moves smoothly for the first 3-5 seconds before it begins progressively slowing down more and more

solemn wharf
#

maybe you are overloading the screen

fallen pier
#

yes, but with how i understand it i don't know how to lessen the load, because i don't know how to draw the background without it being in the function that updates every frame

edgy sparrow
#

I'm not familiar with how tkinter's canvas works. I'm not sure it's the best way to implement a game though... Have you tried PyGame? It's designed to do this kinda stuff...

solemn wharf
fallen pier
edgy sparrow
#

My guess would be that it's slow because you're creating new objects every update. From a quick Google search it seems that you need to create each object once and then move it as necessary, I didn't find an example of how though

fallen pier
#

alright, i think that its a little bit more complicated then that because the projects necessitates that everything needs to be a function, but thanks nonetheless

edgy sparrow
#

This wouldn't change the usage of functions. It'd change how you update each item on the screen

#

Rather than creating a new one every time, you'd create them once. Then when you need to update them, rather than creating a new one, you'd instead update the existing ones.

fallen pier
#

right but one pf the functions is call game and it updates every frame so maybe i can add a new function later on, thanks!

edgy sparrow
#

You'd just change that function to update all your objects

vagrant owl
#

For example, if the BG never moves, can’t you create it once? and never need to remake the object?