0

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)
2
Contributors
4
Replies
16
Views
3 Years
Discussion Span
Last Post by NiescierJ
Featured Replies
  • 1

    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. Read More

  • 3

    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 = … Read More

1

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.

0

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

3

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()

Edited by woooee

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.