python 异常和弹出框

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:\n%s"%ex)
    tkinter.messagebox.showinfo("showinfo","Error Message:\n%s"%ex)
    tkinter.messagebox.showwarning("showwarning","Error Message:\n%s"%ex)
    tkinter.messagebox.showerror("showerror","Error Message:\n%s"%ex)
    tkinter.messagebox.askquestion("askquestion","Error Message:\n%s"%ex)
    tkinter.messagebox.askokcancel("askokcancel","Error Message:\n%s"%ex)
    tkinter.messagebox.askretrycancel("askretrycancel","Error Message:\n%s"%ex)
    

 

posted @ 2017-08-29 22:46  aWolfMan  阅读(1533)  评论(0编辑  收藏  举报