August 2018
Intermediate to advanced
366 pages
10h 14m
English
The simpledialog.Dialog class can be used to implement simple OK/cancel dialogs, and allows us to provide any body of the dialog with custom content.
We can use it to add a message and a list to a dialog and let the user make a selection:
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) def body(self, parent): self._message = tkinter.Message(parent, text=self._text, aspect=400) self._message.pack(expand=1, fill=tkinter.BOTH) self._list = tkinter.Listbox(parent) self._list.pack(expand=1, fill=tkinter.BOTH, side=tkinter.TOP) for item in self._items: ...