I'm attempting to implement a simple Pong game in Python using Tkinter, but unfortunately I'm having some major issues with flickering. I'm using a Canvas widget that covers the entire window and I'm drawing rectangles on said canvas many times per second. When I do this all drawn rectangles flicker regularly while the game is running, disappearing for a fraction of a second before appearing again.
A simple example of the logic I use for drawing in my game can be seen below, by running it you should be able to see the flickering in action:
from tkinter import *
import threading, time
def loop():
FRAME_TIME = 1 / 60
while True:
render()
time.sleep(FRAME_TIME)
def render():
canvas.delete(ALL)
canvas.create_rectangle(0, 0, WIDTH, HEIGHT, fill='black')
WIDTH = 800
HEIGHT = 600
root = Tk()
canvas = Canvas(root, width=800, height=600)
canvas.pack()
threading.Thread(target=loop, daemon=True).start()
root.mainloop()
Any ideas as to what is causing it?