0
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.

3
  • 1
    what happens if you print(seconds_entry_get) at the start of your else statement? Does it look like a number? Commented Jun 15, 2021 at 17:41
  • if seconds_entry_get == type(str): does not do what you think it does, I assume what you were trying to do was if isinstance(seconds_entry_get, str): Commented Jun 15, 2021 at 17:41
  • This is quite wrong because <Entry>.get() always returns a str. Commented Jun 15, 2021 at 18:04

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.