August 2018
Intermediate to advanced
366 pages
10h 14m
English
simpledialog.Dialog creates a dialog with Ok and Cancel buttons by default and only provides a title.
In our case, apart from creating the dialog itself, we also want to keep the message of the dialog and the items available for selection, so that we can show them to the user. Also, by default, we want to set that no item was selected yet. Finally, we can call simpledialog.Dialog.__init__, as once it's called, the main thread will block and we can't do anything else until the dialog is dismissed:
import tkinter from tkinter import simpledialog class ChoiceDialog(simpledialog.Dialog): def __init__(self, parent, title, text, items): self.selection = None self._items = items self._text = text super().__init__(parent, title=title) ...