Search on blog:

Tkinter Example: use Checkbutton to start and stop timer [GB]

When you select Checkbutton then it start timer (but without displayint it).

When you deselect Checkbutton then it stop timer and display time cumulated with previous time

import tkinter as tk
import time

# --- functions ---

def func():
    global total
    global time_start

    if cb_var.get():
        time_start = time.time()
    else:
        total += (time.time() - time_start)
        label['text'] = 'Total: {:.2f}s'.format(total)

# --- main ---

total = 0
time_start = 0

root = tk.Tk()

cb_var = tk.BooleanVar()

label = tk.Label(root, text='Total: 0.00s')
label.pack()

cb = tk.Checkbutton(root, text='Running ...', variable=cb_var, command=func)
cb.pack()

root.mainloop()
If you like it
Buy a Coffee