The following code works as expected unless the button is hit again while the function is being executed. I tried disabling the button in the function and re-enabling it when the function finishes but it is not working. What do I need to do to make this work?
import tkinter as tk
from tkinter import scrolledtext
root = tk.Tk()
root.title('Test Case')
root.geometry('850x300')
root.configure(background='ivory3')
label_fill = tk.Label(root, width = "80", height = "1", bg = 'ivory3')
label_fill.grid(row=1, columnspan=3)
textw = scrolledtext.ScrolledText(root, width=18, height=2)
textw.grid(column=0, row=2, sticky='nsew')
textw.tag_configure('tag-left', justify='left')
textw.config(background='light grey', foreground='green',
font='arial 60 bold', wrap='word', relief='sunken', bd=5)
def func_ex(count=None):
btn = tk.Button(state=tk.DISABLED)
if count is not None:
if count <= 31:
if (count % 3) == 1:
txt = 'START'
sleep = 2000
if (count % 3) == 2:
txt = 'HOLD'
sleep = 5000
if (count % 3) == 0:
txt = 'END'
sleep = 1000
if count == 31:
txt = 'DONE'
sleep = 1
textw.delete('1.0', 'end')
textw.insert('end', txt, 'tag-left')
count += 1
root.after(sleep, lambda: func_ex(count))
else:
func_ex(1)
btn = tk.Button(state=tk.NORMAL)
btn = tk.Button(root, text='Start Test Case', bg='light grey',
width=18,font='arial 12', relief='raised', bd=5,
command=func_ex)
btn = btn.grid(row=0, column=0)
root.mainloop()