When more than two choices are available to the user, the best way to list them is through lists. The tkinter
module provides a ListBox
, which allows us to show a set of entries in a scrollable widget for the user to pick from.
We can use this to implement a dialog where the user can pick one of many options and grab the chosen one:
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...