Manual progress bar python
<p>Im trying to make a code so that it displays all numbers from 1 to 100 to show as its loading something.</p>

<pre><code>for i in range(101):
        self.new = Label(self.label_progress, text=i)
        time.sleep(1)
        self.new.place(in_= self.label_progress)
        if i == 100:
            self.new1=Label(self.label_progress, text="the download is complete")
            self.new1.place(in_=self.label_progress, x=50)
</code></pre>

<p>but it seems like it doesnt want to show each number untill the loop is complete, at the end it just shows a 100. Any suggestions on how to fix it?</p>

<p><code>tkinter</code> has <code>mainloop()</code> which runs all the time and does many thing - ie. it updates data in widget, redraws widgets, executes your function. When <code>mainloop()</code> executes your function then it can't updates/redraws widgets till your function stop running. You can use <code>root.update()</code> in your function to force tkinter to update/readraw widgets.</p>

<p>Or you can use </p>

<pre><code>root.after(miliseconds, function_name) 
</code></pre>

<p>to periodically execute function which will update <code>Label</code> . And between executions <code>tkinter</code> will have time to update/redraw widgets.</p>

<p>Examples which use <code>after</code> to update time in <code>Label</code>:</p>

<p><a href="https://github.com/furas/my-python-codes/tree/master/tkinter/timer-using-after" rel="nofollow">https://github.com/furas/my-python-codes/tree/master/tkinter/timer-using-after</a></p>

<hr>

<p><strong>BTW:</strong> <code>tkinter</code> has <code>ttk.Progressbar</code></p>

<p>Example code: <a href="http://stackoverflow.com/a/24770800/1832058">http://stackoverflow.com/a/24770800/1832058</a></p>

<p><img src="http://i.stack.imgur.com/WNzEZ.png" alt="enter image description here"></p>

python loops tkinter