What's the easiest way to genera开发者_StackOverflow社区te 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.
@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.
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.
You can get a one-liner using tkinter.
import tkMessageBox
tkMessageBox.showerror('error title', 'error message')
Here is some documentation for pop-up dialogs.
If i recall correctly (don't have Windows box at the moment), the ctypes
way is:
import ctypes
ctypes.windll.user32.MessageBoxW(None, u"Error", u"Error", 0)
ctypes is a standard module.
Note: For Python 3.x you don't need the u
prefix.
Check out the GUI section of the Python Wiki for info on message boxs
精彩评论