Last change
on this file since 7244 was
6351,
checked in by rwilson, 16 years ago
|
Cleanup and attempt to get matplotlib 0.98.5.2 working.
|
File size:
1.2 KB
|
Line | |
---|
1 | ''' |
---|
2 | A small function to put an error message on the screen with Tkinter. |
---|
3 | |
---|
4 | Used by Windows programs started from a desktop icon. |
---|
5 | ''' |
---|
6 | |
---|
7 | import string |
---|
8 | from Tkinter import * |
---|
9 | |
---|
10 | ## |
---|
11 | # @brief Show an error message in a GUI environment. |
---|
12 | # @param msg The message to display. |
---|
13 | # @note The message may contain embedded \n chars. |
---|
14 | def tkinter_error(msg): |
---|
15 | ###### |
---|
16 | # Define the Application class |
---|
17 | ###### |
---|
18 | |
---|
19 | class Application(Frame): |
---|
20 | def createWidgets(self): |
---|
21 | self.LABEL = Label(self) |
---|
22 | self.LABEL["text"] = self.text |
---|
23 | self.LABEL["fg"] = "black" |
---|
24 | self.LABEL["bg"] = "yellow" |
---|
25 | self.LABEL["justify"] = "left" |
---|
26 | self.LABEL["font"] = "9x15bold" |
---|
27 | self.LABEL.pack() |
---|
28 | |
---|
29 | def __init__(self, text, master=None): |
---|
30 | self.text = text |
---|
31 | Frame.__init__(self, master) |
---|
32 | self.pack() |
---|
33 | self.createWidgets() |
---|
34 | |
---|
35 | |
---|
36 | # get the message text |
---|
37 | msg = '\n' + msg.strip() + '\n' |
---|
38 | |
---|
39 | msg = string.replace(msg, '\r', '') |
---|
40 | msg = string.replace(msg, '\n', ' \n ') |
---|
41 | |
---|
42 | app = Application(msg) |
---|
43 | app.master.title('ERROR') |
---|
44 | app.mainloop() |
---|
45 | |
---|
46 | |
---|
47 | if __name__ == '__main__': |
---|
48 | tkinter_error('A short message:\nHello, world!') |
---|
Note: See
TracBrowser
for help on using the repository browser.