I was creating a to-do list program for my school project and faced this error when implementing a timer into the code following is the code:
from tkinter import *
root =Tk()
root.geometry("500x500")
font_tuple=("Proxima Nova", 15, "bold")
timer_frame=Frame(root)
timer_frame.pack()
sec=StringVar()
mins=StringVar()
hrs=StringVar()
time_sec_list =Entry(timer_frame, text=sec, font=font_tuple, width=2)
time_sec_list.grid(row=0, column=4, padx=10)
time_min_list =Entry(timer_frame, font=font_tuple, width=2)
time_min_list.grid(row=0, column=3, padx=10)
time_hrs_list =Entry(timer_frame, font=font_tuple, width=2)
time_hrs_list.grid(row=0, column=2, padx=10)
enter_time=Label(timer_frame, font=font_tuple,text="Enter time:", bg="#E0B4A3")
enter_time.grid(row=0, column=1)
def timer1():
try:
times = int(str(time_hrs_list.get()))*3600+ int(str((time_min_list.get())))*60 + int(str(time_sec_list.get()))
while times > -1:
minute,second = (times // 60 , times % 60)
hour =0
if minute > 60:
hour , minute = (minute // 60 , minute % 60)
sec.set(second)
mins.set(minute)
hrs.set(hour)
mroot.update()
time.sleep(1)
if(times == 0):
time_sec_list.set('00')
time_min_list.set('00')
time_hrs_list.set('00')
times -= 1
except Exception as e:
print(e)
start_timer_b=Button(timer_frame, text="Start timer", command=timer1, pady=10)
start_timer_b.grid(row=1, column=3)
can anybody pls help me with why I am unable to convert the type of the data all help is appreciated there are 2 problems I am facing with the following code :
- the StringVar() is not showing in the entry widget that is its not showing 00 when I set it to 00
- the timer is not working it is unable to identify that the data inputted into the entry widget is a number and can be converted into a string and is excepting it as a pure string with characters