when i'm pressing the "start program" button it starts a 5 sec task and block the GUI.
as i understand i need to use Threading so each button will work independently from the GUI.
I'm stuck for almost a month already, can someone show me how can execute def start_Button(self): function using threading?
from tkinter import *
def __init__(self, master=None):
self.master = master
self.var = IntVar()
quitButton = Button(self, text="Exit", command=self.client_exit)
startButton = Button(self, text="Start Program", command=self.start_Button)
print('Program is starting')
for i in range (5):
root = Tk()
app = Window(root)
There are a lot of important questions to ask before you jump into threading for the first time, but by and large the most important question is "how do I want to communicate between my threads?" In your minimal example you don't require any communication at all, however in your real code
start_Button may be doing some Work and returning data back to the GUI. If that's the case, you have more work to do. Please clarify that as a comment if that's the case.
For the minimal example, it's actually quite easy.
class Window(tkinter.Frame): # the rest of your GUI class as written, but change... def start_Button(self): def f(): # this is the actual function to run print('Program is starting') for i in range (5): print(i) time.sleep(1) t = threading.Thread(target=f) t.start()