Skip to Content
Modern Python Standard Library Cookbook
book

Modern Python Standard Library Cookbook

by Alessandro Molina
August 2018
Intermediate to advanced
366 pages
10h 14m
English
Packt Publishing
Content preview from Modern Python Standard Library Cookbook

How to do it...

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: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Advanced Python Development: Using Powerful Language Features in Real-World Applications

Matthew Wilkes

Publisher Resources

ISBN: 9781788830829Supplemental Content