Show the given text in a scrollable window with a 'close' button. If modal is left True, users cannot interact with other windows until the textview window is closed. parent - parent of this dialog title - string which is title of popup dialog contents - tex
(self, parent, title, contents, modal=True, wrap=WORD,
*, _htest=False, _utest=False)
| 106 | "A simple text viewer dialog for IDLE." |
| 107 | |
| 108 | def __init__(self, parent, title, contents, modal=True, wrap=WORD, |
| 109 | *, _htest=False, _utest=False): |
| 110 | """Show the given text in a scrollable window with a 'close' button. |
| 111 | |
| 112 | If modal is left True, users cannot interact with other windows |
| 113 | until the textview window is closed. |
| 114 | |
| 115 | parent - parent of this dialog |
| 116 | title - string which is title of popup dialog |
| 117 | contents - text to display in dialog |
| 118 | wrap - type of text wrapping to use ('word', 'char' or 'none') |
| 119 | _htest - bool; change box location when running htest. |
| 120 | _utest - bool; don't wait_window when running unittest. |
| 121 | """ |
| 122 | super().__init__(parent) |
| 123 | self['borderwidth'] = 5 |
| 124 | # Place dialog below parent if running htest. |
| 125 | x = parent.winfo_rootx() + 10 |
| 126 | y = parent.winfo_rooty() + (10 if not _htest else 100) |
| 127 | self.geometry(f'=750x500+{x}+{y}') |
| 128 | |
| 129 | self.title(title) |
| 130 | self.viewframe = ViewFrame(self, contents, wrap=wrap) |
| 131 | self.protocol("WM_DELETE_WINDOW", self.ok) |
| 132 | self.button_ok = Button(self, text='Close', |
| 133 | command=self.ok, takefocus=False) |
| 134 | self.viewframe.pack(side='top', expand=True, fill='both') |
| 135 | |
| 136 | self.is_modal = modal |
| 137 | if self.is_modal: |
| 138 | self.transient(parent) |
| 139 | self.grab_set() |
| 140 | if not _utest: |
| 141 | self.wait_window() |
| 142 | |
| 143 | def ok(self, event=None): |
| 144 | """Dismiss text viewer dialog.""" |
nothing calls this directly
no test coverage detected