Create a frame for viewing text with a "Close" button. parent - parent widget for this frame contents - text to display wrap - type of text wrapping to use ('word', 'char' or 'none') The Text widget is accessible via the 'text' attribute.
(self, parent, contents, wrap='word')
| 72 | class ViewFrame(Frame): |
| 73 | "Display TextFrame and Close button." |
| 74 | def __init__(self, parent, contents, wrap='word'): |
| 75 | """Create a frame for viewing text with a "Close" button. |
| 76 | |
| 77 | parent - parent widget for this frame |
| 78 | contents - text to display |
| 79 | wrap - type of text wrapping to use ('word', 'char' or 'none') |
| 80 | |
| 81 | The Text widget is accessible via the 'text' attribute. |
| 82 | """ |
| 83 | super().__init__(parent) |
| 84 | self.parent = parent |
| 85 | self.bind('<Return>', self.ok) |
| 86 | self.bind('<Escape>', self.ok) |
| 87 | self.textframe = ScrollableTextFrame(self, relief=SUNKEN, height=700) |
| 88 | |
| 89 | text = self.text = self.textframe.text |
| 90 | text.insert('1.0', contents) |
| 91 | text.configure(wrap=wrap, highlightthickness=0, state='disabled') |
| 92 | color_config(text) |
| 93 | text.focus_set() |
| 94 | |
| 95 | self.button_ok = button_ok = Button( |
| 96 | self, text='Close', command=self.ok, takefocus=False) |
| 97 | self.textframe.pack(side='top', expand=True, fill='both') |
| 98 | button_ok.pack(side='bottom') |
| 99 | |
| 100 | def ok(self, event=None): |
| 101 | """Dismiss text viewer dialog.""" |