Tkinter Update intvar in label
<p>I am trying to have an integer to constantly change inside a label using Tkinter.</p>

<pre><code>import tkinter
root = tkinter.Tk()
var  = tkinter.IntVar()

label  = tkinter.Label(root, textvariable=var)
button = tkinter.Button(root, command=lambda: var.set(var.get() + 1), text='+1')

label.pack()
button.pack()
root.mainloop()
</code></pre>

<p>The closest I have come to what I need after searching is to the example above. However you need to click a button for the integer to change, What I need is without anything for the user to do, for the integer to change.</p>

<p>I have an array which is constantly getting bigger while the program is running which I need to print its length each time there is one new element appended to it.</p>

<p>Update: Working answer:</p>

<pre><code>import tkinter
import time
root = tkinter.Tk()
var  = tkinter.IntVar()

label  = tkinter.Label(root, textvariable=var)
label.pack()
def update_Value():
    for i in range(5):
        time.sleep(1)
        var.set(i)
        root.update()
root.after(0, update_Value)
root.mainloop()
</code></pre>

<p>You can use <code>root.after(time_in_milisecond, function_name)</code> to call function which change value in label without user interaction.</p>

<p>Example: <a href="https://github.com/furas/my-python-codes/blob/master/tkinter/timer-using-after/clock-function.py" rel="nofollow">showing current time using after</a></p>

<hr>

<p>Here's an example of the code from the question, using <code>after</code> to automatically call the function after <code>mainloop</code> starts:</p>

<pre><code>import tkinter
import time
root = tkinter.Tk()
var  = tkinter.IntVar()

label  = tkinter.Label(root, textvariable=var)
label.pack()

def function():
    for i in range(5):
        var.set(i)
        root.update()
        time.sleep(1) # to slow down

root.after(1, function)

root.mainloop()
</code></pre>

python tkinter