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

We can create a dialog function to hide the minor differences between dialog types and call the appropriate dialog depending on the kind of request:

from tkinter import messagebox from tkinter import simpledialog from tkinter import filedialog def dialog(ask, title, message=None, **kwargs): for widget in (messagebox, simpledialog, filedialog): show = getattr(widget, 'ask{}'.format(ask), None) if show: break else: raise ValueError('Unsupported type of dialog: {}'.format(ask)) options = dict(kwargs, title=title) for arg, replacement in dialog._argsmap.get(widget, {}).items(): options[replacement] = locals()[arg] return show(**options) dialog._argsmap = { messagebox: {'message': 'message'}, simpledialog: {'message': 'prompt'} ...
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