Home > Software design >  Is there away to use ValueError terminal output?
Is there away to use ValueError terminal output?

Time:04-18

I was wondering if there is a way to use the terminal output for ValueError when found? In my case, it works perfectly as is. See attached image. If I could just display it on my GUI, it would instantly improve my UX. I can't imagine having to write codes to capture the error in question '*5'. Does it have something to do with message.py? How do I get there?

on my wish list

as per Amir

CodePudding user response:

In general, this is how you catch and print an exception:

try:
    # doing something that raises an error
    a = float('*5')
except ValueError as e:
    error_msg = repr(e)  # this is the error message
    print('Got a ValueError exception!')
    print(error_msg)

CodePudding user response:

You should be able to assign a StringVar to a label and then bind the label to the StringVar and then set the StringVar to the error message from the ValueError.

status = tk.StringVar lblStatus = tk.Label(master, textvariable=status) ...

status.set(str(ValueError))

  • Related