79804895

Date: 2025-10-30 14:59:16
Score: 0.5
Natty:
Report link

Thank you all. The problem was that the term "global b" shoud have been at the begining of all the funkcions.

import tkinter,time

canvas=tkinter.Canvas(width=500,height=500,bg="white")
canvas.pack()

canvas.create_text(250,250,text="00:00:00",font="Arial 70 bold")

def cl_e():
    global b
    b=False
    clock()

def cl_s():
    global b
    b=True
    clock()

def clock():
    global b
    h=0
    m=0
    s=0
    while b:
        canvas.delete("all")
        if s<60:
            s+=1
            time.sleep(1)           
        elif m<60:
            s=0
            m+=1
        else:
            s=0
            m=0
            h+=1
        if h<10 and m<10 and s<10:
            canvas.create_text(250,250,text="0"+str(h)+":0"+str(m)+":0"+str(s),font="Arial 70 bold")
        elif h<10 and m<10 and s>=10:
            canvas.create_text(250,250,text="0"+str(h)+":0"+str(m)+":"+str(s),font="Arial 70 bold")
        elif h<10 and m>=10 and s<10:
            canvas.create_text(250,250,text="0"+str(h)+":"+str(m)+":0"+str(s),font="Arial 70 bold")
        elif h<10 and m>=10 and s>=10:
            canvas.create_text(250,250,text="0"+str(h)+":"+str(m)+":"+str(s),font="Arial 70 bold")
        elif h>=10 and m<10 and s<10:
            canvas.create_text(250,250,text=str(h)+":0"+str(m)+":0"+str(s),font="Arial 70 bold")
        elif h>=10 and m<10 and s>=10:
            canvas.create_text(250,250,text=str(h)+":0"+str(m)+":"+str(s),font="Arial 70 bold")
        elif h>=10 and m>=10 and s<10:
            canvas.create_text(250,250,text=str(h)+":"+str(m)+":0"+str(s),font="Arial 70 bold")
        else:
            canvas.create_text(250,250,text=str(h)+":"+str(m)+":"+str(s),font="Arial 70 bold")
        canvas.update()

start=tkinter.Button(text="Start",command=cl_s)
end=tkinter.Button(text="End",command=cl_e)
start.pack()
end.pack()
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Faith