I have a Tkinter-GUI in Python 3.3 with a progress bar and a button that starts another thread. This thread fills the progress bar within 10 seconds and also prints the numbers from 0 to 99 on the console during this time.
It works as it is supposed to as long as I am not moving or resizing the GUI window. If I delete the marked line progress.step(1)
so that the worker-thread doesn't touch the progress bar and as a consequence doesn't affect the GUI at all, it prints the numbers continuously on the console even if I am manipulating the window.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from tkinter import *
import tkinter.ttk as ttk
import _thread
import time
root = Tk()
def start():
_thread.start_new_thread(thread, ())
def thread():
for i in range(0, 100):
time.sleep(0.1)
progress.step(1) #<-----
print(i)
progress = ttk.Progressbar()
progress.pack()
button = Button(root, text="Start", command=start)
button.pack()
root.mainloop()
Why is this happening and what is usually done to avoid worker-thread interruption by GUI manipulation?
Thanks in advance!