I was trying to create a counter gui and from what I've tried it was working but I need to use between the 3 concepts the Threading, Concurrency and Parallelism. Just want to ask what would be the best or simplest? (will insert/edit the code after)
What I have tried:
from tkinter import *
window = Tk()
window.geometry('300x100')
window.title('Counter')
window.resizable(0, 0)
counter = -1
running = False
def counter_label(lbl):
def count():
if running:
global counter
if counter == -1:
display = "0"
else:
display = str(counter)
lbl['text'] = display
lbl.after(1000, count)
counter += 1
count()
def StartTimer(lbl):
global running
running = True
counter_label(lbl)
start_btn['state'] = 'disabled'
stop_btn['state'] = 'normal'
def StopTimer():
global running
start_btn['state'] = 'normal'
stop_btn['state'] = 'disabled'
running = False
lbl = Label(window, text="0", width=8)
lbl.grid(column=4, row=2)
lbl.place(x=170, y=15)
label_msg = Label(window, text="Counter")
label_msg.place(x=100, y=15)
start_btn = Button(window, text='Start Counting', width=16, command=lambda: StartTimer(lbl))
start_btn.grid(column=2, row=3)
stop_btn = Button(window, text='Stop Counting', width=16, state='disabled', command=StopTimer)
stop_btn.grid(column=5, row=3)
start_btn.place(x=25, y=40)
stop_btn.place(x=155, y=40)
window.mainloop()