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

For this recipe, perform the following steps:

  1. We will make a MessageBox.show method which we can use to show a message box whenever we need it. The MessageBox class will be able to show message boxes with just OK or OK/cancel buttons:
import curses
import textwrap
import itertools


class MessageBox(object):
    @classmethod
    def show(cls, message, cancel=False, width=40):
        """Show a message with an Ok/Cancel dialog.

        Provide ``cancel=True`` argument to show a cancel button  too. Returns the user selected choice: - 0 = Ok - 1 = Cancel """ dialog = MessageBox(message, width, cancel) return curses.wrapper(dialog._show) def __init__(self, message, width, cancel): self._message = self._build_message(width, message) self._width = width ...
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