Start New Discussion within our Software Development Community

Heyho users;

I need to update a label in a window every x seconds to get an variabel ("res") which is up to date.
My current code:

def init(win):
    win.minsize(800, 600)
    lab=Label(win, text="Aktuell: " + res +" Euro", bg='#40E0D0', fg='#FF0000'), y=30)

def updater(win):
    ids = lab.after(1000, updater)
    print ("Done")  

(I don't post the complete code, I think this is enough to understand)
Nothing happens with the code above.
Any idea how to fix?
I need to stop the updater when window "wín" is being closed, how to do this, because I don't want to get errors in cmd.

All the best;

There is more than one way to skin that cat. I use a tkinter variable and update it. Note that you have to call updater() to get the whole thing started.

    import Tkinter as tk     ## Python 2.x
except ImportError:
    import tkinter as tk     ## Python 3.x

class UpdateLabel():
    def __init__(self): = tk.Tk()"Ausgangsposition"), 600)
        self.ctr = 0
        self.tk_var = tk.StringVar()
        lab=tk.Label(, textvariable=self.tk_var,
                       bg='#40E0D0', fg='#FF0000'), y=30)

    def updater(self):
        self.ctr += 1
        if self.ctr < 10:
  , self.updater)

This article has been dead for over six months. Start a new discussion instead.