I've tried by now several methods found online but I can't seem to find a solution. What I want to create is to enable a while loop with a button and disable it with another button. The main issue, is that while the loop is active, it freezes my GUI when I press my "disable" button. The while loop does stop, but I have to kill the executable in task manager and restart it in order to re-enable the while loop.
Code:
from tkinter import *
import time
top = Tk()
top.title("Corsair")
top.geometry('100x100')
top.resizable(False, False)
def b1():
while True:
[MY MAIN CODE]
# if But2.is_pressed:
# break
but1 = Button(top, image = onbutton, text ="On", command = b1)
but2 = Button(top, image = offbutton, text ="Off", pady = 100, padx = 10, command = top.destroy)
but1.pack()
but2.pack()
top.mainloop()
I've tried; if But2.is_pressed to break the code, which freezes the GUI.
Make but2 to destroy top window, which freezes the GUI.
I've tried ;
x = 1
def b1():
while True:
if x == 1:
[MY MAIN CODE]
else:
break
def b2():
x = 0
but1 = Button(top, image = onbutton, text ="On", command = b1)
but2 = Button(top, image = offbutton, text ="Off", pady = 100, padx = 10, command = b2)
but3 = Button(top, text ="Exit", pady = 100, padx = 20, command = top.destroy)