import tkinter.messagebox try: fileContent = open("abnormal.txt") fileContent.close() print("over") #把异常消息赋予一个"ex"变量 except Exception as ex: print(ex) tkinter.messagebox.showinfo("Alert",ex) tkinter.messagebox.askyesnocancel("askyesnocancel","Error Message: %s"%ex) tkinter.messagebox.showinfo("showinfo","Error Message: %s"%ex) tkinter.messagebox.showwarning("showwarning","Error Message: %s"%ex) tkinter.messagebox.showerror("showerror","Error Message: %s"%ex) tkinter.messagebox.askquestion("askquestion","Error Message: %s"%ex) tkinter.messagebox.askokcancel("askokcancel","Error Message: %s"%ex) tkinter.messagebox.askretrycancel("askretrycancel","Error Message: %s"%ex)