Initialize a dialog. Arguments: parent -- a parent window (the application window) title -- the dialog title
(self, parent, title = None)
| 97 | ''' |
| 98 | |
| 99 | def __init__(self, parent, title = None): |
| 100 | '''Initialize a dialog. |
| 101 | |
| 102 | Arguments: |
| 103 | |
| 104 | parent -- a parent window (the application window) |
| 105 | |
| 106 | title -- the dialog title |
| 107 | ''' |
| 108 | master = parent |
| 109 | if master is None: |
| 110 | master = _get_temp_root() |
| 111 | |
| 112 | Toplevel.__init__(self, master) |
| 113 | |
| 114 | self.withdraw() # remain invisible for now |
| 115 | # If the parent is not viewable, don't |
| 116 | # make the child transient, or else it |
| 117 | # would be opened withdrawn |
| 118 | if parent is not None and parent.winfo_viewable(): |
| 119 | self.transient(parent) |
| 120 | |
| 121 | if title: |
| 122 | self.title(title) |
| 123 | |
| 124 | _setup_dialog(self) |
| 125 | |
| 126 | self.parent = parent |
| 127 | |
| 128 | self.result = None |
| 129 | |
| 130 | body = Frame(self) |
| 131 | self.initial_focus = self.body(body) |
| 132 | body.pack(padx=5, pady=5) |
| 133 | |
| 134 | self.buttonbox() |
| 135 | |
| 136 | if self.initial_focus is None: |
| 137 | self.initial_focus = self |
| 138 | |
| 139 | self.protocol("WM_DELETE_WINDOW", self.cancel) |
| 140 | |
| 141 | _place_window(self, parent) |
| 142 | |
| 143 | self.initial_focus.focus_set() |
| 144 | |
| 145 | # wait for window to appear on screen before calling grab_set |
| 146 | self.wait_visibility() |
| 147 | self.grab_set() |
| 148 | self.wait_window(self) |
| 149 | |
| 150 | def destroy(self): |
| 151 | '''Destroy the window''' |
no test coverage detected