Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to throw an error window in Python in Windows

Tags:

python

windows

What's the easiest way to generate an error window for a Python script in Windows? Windows-specific answers are fine; please don't reply how to generate a custom Tk window.

like image 476
Scribble Master Avatar asked Jul 29 '10 18:07

Scribble Master


People also ask

How do you pop up errors in Python?

Build A Paint Program With TKinter and Python The messagebox property has different types of built-in popup windows that the users can use in their applications. If you need to display the error messagebox in your application, you can use showerror("Title", "Error Message") method.

What is Windows error in Python?

WindowsError is a subclass of OSError . From the exceptions documentation: Raised when a Windows-specific error occurs or when the error number does not correspond to an errno value.

Can you do an if error in Python?

We can also do this in Python. What you need to look at is the very last line - ValueError. This is the type of error and changes depending on what went wrong. So to setup an IFERROR you simply add in a TRY and EXCEPT.


2 Answers

If you need a GUI error message, you could use EasyGui:

>>> import easygui as e
>>> e.msgbox("An error has occured! :(", "Error")

Otherwise a simple print("Error!") should suffice.

like image 75
John Howard Avatar answered Oct 27 '22 06:10

John Howard


@Constantin is almost correct, but his example will produce garbage text. Make sure that the text is unicode. I.e.,

ctypes.windll.user32.MessageBoxW(0, u"Error", u"Error", 0)

...and it'll work fine.

like image 44
Chris Avatar answered Oct 27 '22 07:10

Chris