So, I'm working on a timer using Python and Tkinter's GUI. To do so, I intend to convert the minutes into seconds (as seen in my code) and use Python's time.sleep command to count down (not yet implemented).
from tkinter import *
import time
countdown = Tk()
countdown.geometry('500x300')
minute = Text(countdown, height = 0.01, width = 5)
minute.place(x=100, y=100)
minlabel = Label(text = "Input Minutes", font = ("MS Sans Serif", 10), bg = 'Light Blue')
minlabel.place(x=85, y = 80)
def go(event):
minseconds = int(minute.get("1.0", END))*60
print(int(minseconds))
countdown.bind('<Return>', go)
countdown.mainloop()
However, when I convert it to minutes, it works the first time (I.E, when I input 3, 180 returns), but any time after that I get this:
ValueError: invalid literal for int() with base 10: '3\n3\n\n'
Any idea what could be causing this? And why it works the first time but then stops working? Thanks :)
'3\n3\n\n'contains more than numbers.'\n'means a line break point, you need to filter the string in the way you want to work with. Maybe dont usetk.ENDrather an known index.