Hey i am new to python and i am trying to update my GUI every 3 seconds 4 times. I have tried time.sleep() but it doesnt work. Any ideas?

for i in range(4):
    #creates 10 circles randomly on the canvas
    for _ in range(10):
         circle1= Circle(canvas, random.randint(1,750), random.uniform(1,450), "red")
    time.sleep(3)

GUI's have their own "sleep" type methods that should be used. However each GUI uses a different function name so it depends on the GUI toolkit you are using.

I have been using tkinter and messing around with the after() but am having difficulties

Tkinter does not have a Circle class; you use create_oval with circle dimensions. Note that you call the function once and have it call itself recursively for as many times as you want.

try:
    import Tkinter as tk
except:
    import tkinter as tk

class TestAfter():
    def __init__(self):
        self.root=tk.Tk()
        self.ctr = 3
        self.canvas = tk.Canvas(self.root, width=500, height=500)
        self.canvas.grid()
        self.root.after(750, self.update)

        self.root.mainloop()

    def update(self):
        colors = ["black", "red", "green", "blue"]

        if self.ctr > 0:
            start = 50*self.ctr  ## use same values for x & y
            end = start+50
            self.canvas.create_oval(start, start, end, end,
                               fill=colors[self.ctr], width=2)
            self.ctr -= 1
            self.root.after(750, self.update)

TA=TestAfter()

That helps a lot! Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.