I am new to python and have been trying to pause my code by clicking the pause button and resume it as soon as the Resume button is clicked. But the but don't show up during the execution even when I have defined the buttons before the function call. My code is as follows:
from tkinter import *
from time import sleep
master = Tk()
frame = Frame(master)
frame.grid()
global is_asleep
def important_function():
i=0
while(True):
print(i)
i = i+1
sleep(1)
def pause():
#pause the execution
try:
is_asleep = True
while(is_asleep):
sleep(1)
except:
print('Error Occured')
def resume():
is_asleep = False
def stop():
#stop the execution
try:
print('Stop')
exit()
except:
print('Error Occured')
pause = Button(frame, text = "Pause", command = pause).grid()
stop = Button(frame, text = "Stop", command = stop).grid()
resume = Button(frame, text = "Resume", command = resume).grid()
important_function()
master.mainloop()
Please help me understand where am I going wrong.