def sm():
seconds_entry_get = seconds_entry.get()
if seconds_entry_get == type(str):
messagebox.showerror("Wrong Input", "Please type a number or decimal")
else:
converted = int(seconds_entry_get) / 60
conversion_text.delete("1.0", "end")
conversion_text.insert("1.0", converted)
There is some "invalid literal" error and I am having trouble fixing it.
If you want to convert to int
but handle invalid inputs I would instead use try
and except
def sm():
seconds_entry_get = seconds_entry.get()
try:
converted = int(seconds_entry_get) / 60
conversion_text.delete("1.0", "end")
conversion_text.insert("1.0", converted)
except ValueError:
messagebox.showerror("Wrong Input", "Please type a number or decimal")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.