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 it works...

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) ...
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