简体   繁体   中英

How can I make it so that python can check a SystemError in the command prompt

Each time I run the code it always thinks there is a system error even though there might not be

def Check():
    if SystemError:
        Label3 = tk.Label(root, text='Error: Invalid Version\nor already installed', bg="lightblue")
        Label3.config(font=('Ariel', 12), fg='red')
        canvas.create_window(150,330, window=Label3)
    else:
        success = tk.Label(root, text='Success!', bg="lightblue")
        success.config(font=('Ariel', 12), fg='green')
        canvas.create_window(150,330, window=success)

You can surround the code with a try block:

try:
    code_that_may_raise_an_error()
    # continue here when there was no error
except SystemError:
    # handle the error here
else:
    # handle the error free case here

Have a look at online tutorials or the documentation for more informations

That being said, it is not a good sign that this error is raised and there is probably a reason for it that should be taken care of.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM