''' A small function to put an error message on the screen with Tkinter. Used by Windows programs started from a desktop icon. ''' import string from Tkinter import * ## # @brief Show an error message in a GUI environment. # @param msg The message to display. # @note The message may contain embedded \n chars. def tkinter_error(msg): ###### # Define the Application class ###### class Application(Frame): def createWidgets(self): self.LABEL = Label(self) self.LABEL["text"] = self.text self.LABEL["fg"] = "black" self.LABEL["bg"] = "yellow" self.LABEL["justify"] = "left" self.LABEL["font"] = "Courier" self.LABEL.pack() def __init__(self, text, master=None): self.text = text Frame.__init__(self, master) self.pack() self.createWidgets() # get the message text msg = '\n' + msg.strip() + '\n' msg = string.replace(msg, '\r', '') msg = string.replace(msg, '\n', ' \n ') app = Application(msg) app.master.title('ERROR') app.mainloop() if __name__ == '__main__': tkinter_error('A short message:\nHello, world!')