100% found this document useful (1 vote)
115 views

(Ebook) Rapid GUI Programming with Python and Qt. Definitive Guide to PyQt by Mark Summerfield ISBN 9780132354189, 0132354187 - Download the ebook now to never miss important information

The document provides information about the ebook 'Rapid GUI Programming with Python and Qt' by Mark Summerfield, including its ISBN and links for downloading. It also lists several related ebooks and textbooks available for download at ebooknice.com. The content includes a detailed table of contents covering Python programming and GUI programming topics.

Uploaded by

bikikavade93
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
115 views

(Ebook) Rapid GUI Programming with Python and Qt. Definitive Guide to PyQt by Mark Summerfield ISBN 9780132354189, 0132354187 - Download the ebook now to never miss important information

The document provides information about the ebook 'Rapid GUI Programming with Python and Qt' by Mark Summerfield, including its ISBN and links for downloading. It also lists several related ebooks and textbooks available for download at ebooknice.com. The content includes a detailed table of contents covering Python programming and GUI programming topics.

Uploaded by

bikikavade93
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Visit ebooknice.

com to download the full version and


explore more ebooks or textbooks

(Ebook) Rapid GUI Programming with Python and Qt.


Definitive Guide to PyQt by Mark Summerfield ISBN
9780132354189, 0132354187

_____ Click the link below to download _____


https://ebooknice.com/product/rapid-gui-programming-with-
python-and-qt-definitive-guide-to-pyqt-1021714

Explore and download more ebooks or textbooks at ebooknice.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

(Ebook) Rapid GUI Programming with Python and Qt: The Definitive Guide
to PyQt Programming (paperback) by Summerfield, Mark ISBN
9780134393339, 0134393333

https://ebooknice.com/product/rapid-gui-programming-with-python-and-
qt-the-definitive-guide-to-pyqt-programming-paperback-36002214

(Ebook) C++ GUI Programming with Qt 4 by Jasmin Blanchette, Mark


Summerfield ISBN 9780132354165, 0132354160

https://ebooknice.com/product/c-gui-programming-with-qt-4-1268078

(Ebook) C++ GUI programming with Qt 4 by Jasmin Blanchette; Mark


Summerfield ISBN 9780131872493, 0131872494

https://ebooknice.com/product/c-gui-programming-with-qt-4-4098382

(Ebook) GUI Programming with Python: QT Edition by Boudewijn Rempt


ISBN 9780970033048, 0970033044

https://ebooknice.com/product/gui-programming-with-python-qt-
edition-5644898
(Ebook) Programming in Python 3: A Complete Introduction to the Python
Language by Summerfield, Mark ISBN 9780321680563, 0321680561

https://ebooknice.com/product/programming-in-python-3-a-complete-
introduction-to-the-python-language-36002018

(Ebook) Beginning PyQt: A Hands-on Approach to GUI Programming with


PyQt6, 2nd Edition by Joshua M Willman ISBN 9781484279984, 1484279980

https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-with-pyqt6-2nd-edition-42052272

(Ebook) Beginning PyQt: A Hands-on Approach to GUI Programming by


Joshua Willman ISBN 9781484258569, 1484258568

https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-11088500

(Ebook) Beginning PyQt: A Hands-on Approach to GUI Programming by


Willman, Joshua M. ISBN 9781484258569, 1484258568

https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-24240602

(Ebook) Beginning PyQt: A Hands-on Approach to GUI Programming by


Willman, Joshua M. ISBN 9781484258569, 1484258568

https://ebooknice.com/product/beginning-pyqt-a-hands-on-approach-to-
gui-programming-24240606
Rapid GUI Programming
with Python and Qt
The Definitive Guide to PyQt Programming

Mark Summerfield

Upper Saddle River, NJ · Boston · Indianapolis · San Francisco


New York · Toronto · Montreal · London · Munich · Paris · Madrid
Capetown · Sydney · Tokyo · Singapore · Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and the publisher was aware of a trademark
claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied
warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for
incidental or consequential damages in connection with or arising out of the use of the information or
programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or
special sales, which may include electronic versions and/or custom covers and content particular to your
business, training goals, marketing focus, and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
corpsales@pearsontechgroup.com
For sales outside the United States, please contact:
International Sales
international@pearsoned.com
Visit us on the Web: www.prenhallprofessional.com

Library of Congress Cataloging-in-Publication Data


Summerfield, Mark
Rapid GUI programming with Python and Qt : the definitive guide to PyQt programming / Mark
Summerfield.
p. cm.
Includes bibliographical references and index.
ISBN 978-0-13-235418-9 (hardcover : alk. paper)
1. Qt (Electronic resource) 2. Graphical user interfaces (Computer systems) 3. Python (Computer
program language) I. Title.
QA76.9.U83S89 2007
005.1’2—dc22
2007034852
Copyright © 2008 Pearson Education, Inc.
All rights reserved. Printed in the United States of America.
Trolltech®, Qt® and the Trolltech logo are registered trademarks of Trolltech ASA.
ISBN-13: 978-0-13-235418-9
ISBN-10: 0-13-235418-7
Text printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, Michigan.
First printing, October 2007
This book is dedicated to
Andrea Summerfield
This page intentionally left blank
Contents

Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Part I: Python Programming

Chapter 1. Data Types and Data Structures . . . . . . . . . . . . . . . . . . . . . 9


Executing Python Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Variables and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Numbers and Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Integers and Long Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Floats and Decimals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Bytestrings, Unicode Strings, and QStrings . . . . . . . . . . . . . . . . . . 20
Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Built-in Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Chapter 2. Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45


Conditional Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Looping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
List Comprehensions and Generators . . . . . . . . . . . . . . . . . . . . . . . 53
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Generator Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Using Keyword Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Lambda Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Dynamic Function Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Partial Function Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

vii
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Chapter 3. Classes and Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75


Creating Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Methods and Special Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Static Data, and Static Methods and Decorators . . . . . . . . . . . . . 85
Example: The Length Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Collection Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Example: The OrderedDict Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Inheritance and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Modules and Multifile Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Using the doctest Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

Part II: Basic GUI Programming

Chapter 4. Introduction to GUI Programming . . . . . . . . . . . . . . . . . . 111


A Pop-Up Alert in 25 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
An Expression Evaluator in 30 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
A Currency Converter in 70 Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Signals and Slots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

Chapter 5. Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139


Dumb Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Standard Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Modal OK/Cancel-Style Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Smart Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Modeless Apply/Close-Style Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . 155
Modeless “Live” Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163

Chapter 6. Main Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165


Creating a Main Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Actions and Key Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Resource Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

viii
Creating and Using Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Restoring and Saving the Main Window’s State . . . . . . . . . . . . . . 181
Handling User Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Handling File Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Handling Edit Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Handling Help Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202

Chapter 7. Using Qt Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205


Designing User Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Implementing Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Testing Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Chapter 8. Data Handling and Custom File Formats . . . . . . . . . . . . 227


Main Window Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Data Container Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Saving and Loading Binary Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Writing and Reading Using QDataStream . . . . . . . . . . . . . . . . . . . 240
Writing and Reading Using the pickle Module . . . . . . . . . . . . . . . 246
Saving and Loading Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Writing and Reading Using QTextStream . . . . . . . . . . . . . . . . . . . 250
Writing and Reading Using the codecs Module . . . . . . . . . . . . . . . 255
Saving and Loading XML Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Writing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Reading and Parsing XML with PyQt’s DOM Classes . . . . . . . . 259
Reading and Parsing XML with PyQt’s SAX Classes . . . . . . . . . 262
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266

Part III: Intermediate GUI Programming

Chapter 9. Layouts and Multiple Documents . . . . . . . . . . . . . . . . . . . . 269


Layout Policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Tab Widgets and Stacked Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Extension Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Splitters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Single Document Interface (SDI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

ix
Multiple Document Interface (MDI) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301

Chapter 10. Events, the Clipboard, and Drag and Drop . . . . . . . . . 303
The Event-Handling Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Reimplementing Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Using the Clipboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Drag and Drop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Handling Custom Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318

Chapter 11. Custom Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321


Using Widget Style Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Creating Composite Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Subclassing Built-in Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Subclassing QWidget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Example: A Fraction Slider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Example: A Flow-Mixing Widget . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346

Chapter 12. Item-Based Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349


Custom and Interactive Graphics Items . . . . . . . . . . . . . . . . . . . . . . . . . 351
Animation and Complex Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379

Chapter 13. Rich Text and Printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381


Rich Text Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Using QSyntaxHighlighter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
A Rich Text Line Edit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Printing Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Printing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Printing Documents Using HTML and QTextDocument . . . . . . 401
Printing Documents Using QTextCursor and QTextDocument 403
Printing Documents Using QPainter . . . . . . . . . . . . . . . . . . . . . . . . 407
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412

x
Chapter 14. Model/View Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Using the Convenience Item Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Creating Custom Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
Implementing the View Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Implementing the Custom Model . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Creating Custom Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443

Chapter 15. Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445


Connecting to the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Executing SQL Queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Using Database Form Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Using Database Table Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471

Part IV: Advanced GUI Programming

Chapter 16. Advanced Model/View Programming . . . . . . . . . . . . . . . 475


Custom Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Generic Delegates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Representing Tabular Data in Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505

Chapter 17. Online Help and Internationalization . . . . . . . . . . . . . . 509


Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520

Chapter 18. Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521


Creating a TCP Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
Creating a TCP Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534

xi
Chapter 19. Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537
Creating a Threaded Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
Creating and Managing Secondary Threads . . . . . . . . . . . . . . . . . . . . . 544
Implementing a Secondary Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
This Is Not Quite the End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559

Appendix A. Installing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561


Installing on Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Installing on Mac OS X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
Installing on Linux and Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570

Appendix B. Selected PyQt Widgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575

Appendix C. Selected PyQt Class Hierarchies . . . . . . . . . . . . . . . . . . . 581

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585

xii
Foreword
As PyQt’s creator, I’m delighted to see that this book has been written. Al-
though I served as one of the book’s technical reviewers, I’m happy to confess
that I learned a few things myself.
The PyQt documentation covers the APIs of all the PyQt classes. This book
shows you how to use all those classes, how to combine them to create dialogs,
main windows, and entire applications—all of which look good and work well,
with no arbitrary limits, and using a programming language that is a joy
to use.
What I particularly like about the book is that the examples aren’t trivial ones
designed to illustrate a simple point, but are potentially useful in their own
right. The way that different approaches are considered will reward the reader
who wants to develop a deeper understanding of how to apply PyQt to the
development of large scale, production quality applications.
I began the PyQt story back in the late 1990s. I had been using Tcl/Tk for
some time, but I felt that Tk applications looked ugly, especially when I saw
what had been achieved with the first version of KDE. I had wanted to switch
to Python, and so I thought I would combine the change of language with a
change of GUI library.
Initially I used some wrappers that had been written using SWIG, but I con-
cluded that I could produce a more suitable wrapper tool myself. I set to work
creating SIP, and released PyQt 0.1 supporting Qt 1.41 in November 1998.
Development has continued regularly ever since, both to keep up with new re-
leases of Qt and to broaden the scope of PyQt with, for example, the addition
of support tools and improved documentation. By 2000, PyQt 2.0 supported
Qt 2.2 on both Linux and Windows. Qt 3 support appeared in 2001, and
Mac OS X support in 2002. The PyQt4 series began with PyQt 4.0 in June 2006
with support for Qt 4.
My primary goal has always been to allow Python and Qt to work together in
a way that feels natural to Python programmers, while allowing them to do
anything they want in Python that can be done in C++. The key to achieving
this was the development of SIP. This gave me a specialized code generator
over which I had complete control and ensures that Python and Qt will always
fit snugly together.
The essential process of developing and maintaining PyQt is now well estab-
lished. Much of the work is now automated, which means that keeping up with

xiii
new releases of Qt from Trolltech is no longer the problem it once was, and en-
surs that PyQt will continue for years to come.
It’s been very gratifying to watch the growth of the PyQt community over the
years. If this book is part of your introduction to PyQt, then welcome!

— Phil Thompson
Wimborne, Dorset, U.K.
August 25, 2007

xiv
Introduction
This book teaches how to write GUI applications using the Python program-
ming language and the Qt application development framework. The only
essential prior knowledge is that you can program in some object-oriented pro-
gramming language, such as C++, C#, Java, or of course, Python itself. For the
rich text chapter, some familiarity with HTML and with regular expressions is
assumed, and the databases and threading chapters assume some basic knowl-
edge of those topics. A knowledge of GUI programming is not required, since
all the key concepts are covered.
The book will be useful to people who program professionally as part of their
job, whether as full-time software developers, or those from other disciplines,
including scientists and engineers, who need to do some programming in sup-
port of their work. It is also suitable for undergraduate and post-graduate stu-
dents, particularly those doing courses or research that includes a substantial
computing element. The exercises (with solutions) are provided especially to
help students.
Python is probably the easiest to learn and nicest scripting language in
widespread use, and Qt is probably the best library for developing GUI applica-
tions. The combination of Python and Qt, “PyQt”, makes it possible to develop
applications on any supported platform and run them unchanged on all the
supported platforms—for example, all modern versions of Windows, Linux,
Mac OS X, and most Unix-based systems. No compilation is required thanks
to Python being interpreted, and no source code changes to adapt to different
operating systems are required thanks to Qt abstracting away the platform-
specific details. We only have to copy the source file or files to a target machine
that has both Python and PyQt installed and the application will run.
If you are new to Python: Welcome! You are about to discover a language that
is clear to read and write, and that is concise without being cryptic. Python
supports many programming paradigms, but because our focus is on GUI
programming, we will take an object-oriented approach everywhere except in
the very early chapters.
Python is a very expressive language, which means that we can usually write
far fewer lines of Python code than would be required for an equivalent appli-
cation written in, say, C++ or Java. This makes it possible to show some small
but complete examples throughout the text, and makes PyQt an ideal tool for
rapidly and easily developing GUI applications, whether for prototyping or for
production use.

1
2 Introduction

Figure 1 The Eric4 IDE—a PyQt4 application

Since the emphasis of the book is on GUI programming, Part I provides a


fast-paced Python tutorial as well as some PyQt coverage. This material is
clearly marked (just like this paragraph, with “Qt” in the margin) to make
Qt it easy for experienced Python programmers to skip the Python they already
know. Parts II, III, and IV of the book are all PyQt-specific and assume that
readers can already program in Python, whether from previous experience or
from reading Part I.
Quite often in programming we reach decision points when there are several
possible approaches we could take. Reference books and the online documen-
tation identify what classes, methods, and functions are available, and in some
cases provide examples, but such documents rarely provide a broader context.
This book gives the necessary context, highlighting the key decision points for
GUI programming and offering insights into the pros and cons so that you can
decide for yourself what the right policy is for your particular circumstances.
For example, when you create a dialog, should it be modal or modeless? (See
Chapter 5 for an explanation and policy recommendations on this issue.)
PyQt is used to write all kinds of GUI applications, from accounting appli-
cations, to visualization tools used by scientists and engineers. Figure 1, for
example, shows Eric4, a powerful integrated development environment that is
written in PyQt. It is possible to write PyQt applications that are just tens of
lines long, and medium-size projects of 1 000 to 10 000 lines are very common.
Some commercial companies have built 100 000-line PyQt applications, with
Introduction 3

programming teams varying in size from just one person to more than a dozen
people. Many in-house tools are written using PyQt, but because these are of-
ten used to gain competitive advantage, the companies involved generally do
not permit their use of PyQt to be made public. PyQt is also widely used in the
open source world, with games, utilities, visualization tools, and IDEs all writ-
ten using it.
This book is specifically about PyQt4, the Python bindings for the Qt 4 C++
application development framework.★ PyQt4 is provided in the form of ten
Python modules which between them contain around 400 classes and about
6 000 methods and functions. All the example programs have been tested on
Windows, Linux, and Mac OS X, using Python 2.5, Qt 4.2, and PyQt 4.2, and
additionally on Windows and Linux using Qt 4.3 and PyQt 4.3. Backporting to
earlier versions is possible in some cases, but we recommend using the most
up-to-date versions of Python, Qt, and PyQt.
Python, PyQt, and Qt can be used free of charge for noncommercial purposes,
but the license used by Python is different from that used by PyQt and Qt.
Python is available with a very liberal license that allows it to be used to de-
velop both commercial and noncommercial applications. Both PyQt and Qt are
dual-licensed: This essentially allows them to be used to develop noncommer-
cial applications—which must in turn be licensed using an acceptable open
source license such as the GNU General Public License (GPL); or to be used to
develop commercial applications—in this case, a commercial PyQt license and
a commercial Qt license must be purchased.

The Structure of the Book

The book is divided into four parts. Part I is primarily a rapid conversion course
aimed at non-Python programmers who are familiar with an object-oriented
language, although it also has some (clearly marked) PyQt content. Because
the core Python language is mostly simple and is quite small, these chapters
can teach the basics of Python to a sufficient extent that real Python applica-
tions can be written.
If you think that you can pick up the Python syntax simply through reading
it, you might be tempted to skip Part I and dive straight into the GUI pro-
gramming that begins in Part II. The early chapters in Part II include back-
references to the relevant pages in Part I to support readers who choose this
approach. However, even for readers familiar with Python, we recommend
reading about QString in Chapter 1. If you are unfamiliar with partial function
application (currying), it is important to read the subsection that covers this in
Chapter 2, since this technique is sometimes used in GUI programming.


There are also Python bindings for the older Qt 3 library, but there is no reason to use that library
for new projects, especially since Qt 4 offers far more functionality and is easier to use.
4 Introduction

Part II begins by showing three tiny PyQt GUI applications to give an initial
impression of what PyQt programming is like. It also explains some of the
fundamental concepts involved in GUI programming, including PyQt’s high-
level signals and slots communication mechanism. Chapter 5 shows how to
create dialogs and how to create and lay out widgets (“controls” in Windows-
speak—the graphical elements that make up a user interface such as buttons,
listboxes, and such) in a dialog. Dialogs are central to GUI programming: Most
GUI applications have a single main window, and dozens or scores of dialogs,
so this topic is covered in depth.
After the dialogs chapter comes Chapter 6, which covers main windows,
including menus, toolbars, dock windows, and keyboard shortcuts, as well as
loading and saving application settings. Part II’s final chapters show how to
create dialogs using Qt Designer, Qt’s visual design tool, and how to save data
in binary, text, and XML formats.
Part III gives deeper coverage of some of the topics covered in Part II, and in-
troduces many new topics. Chapter 9 shows how to lay out widgets in quite
sophisticated ways, and how to handle multiple documents. Chapter 10 covers
low-level event handlers, and how to use the clipboard as well as drag and drop,
text, HTML, and binary data. Chapter 11 shows how to modify and subclass
existing widgets, and how to create entirely new widgets from scratch, with
complete control over their appearance and behavior. This chapter also shows
how to do basic graphics. Chapter 12 shows how to use Qt 4.2’s new graphics
view architecture, which is particularly suited to handling large numbers of in-
dependent graphical objects. Qt’s HTML-capable rich text engine is covered in
Chapter 13. This chapter also covers printing both to paper and to PDF files.
Part III concludes with two chapters on model/view programming: Chapter 14
introduces the subject and shows how to use Qt’s built-in views and how to
create custom data models and custom delegates, and Chapter 15 shows how
to use the model/view architecture to perform database programming.
Part IV continues the model/view theme, with coverage of three different
advanced model/view topics in Chapter 16. The first section of Chapter 17
describes the techniques that can be used for providing online help, and the
second section explains how to internationalize an application, including how
to use Qt’s translation tools to create translation files. The Python standard
library provides its own classes for networking and for threading, but in the
last two chapters of Part IV we show how to do networking and threading us-
ing PyQt’s classes.
Appendix A explains where Python, PyQt, and Qt can be obtained, and how to
install them on Windows, Mac OS X, and Linux. PyQt is much easier to learn
if you install it and try out some of the exercises, and if you inspect some of
the example code. Appendix B presents screenshots and brief descriptions
of selected PyQt widgets; this is helpful for those new to GUI programming.
Appendix C presents diagrams of some of PyQt’s key class hierarchies; this
Introduction 5

is useful for getting to know what classes PyQt has to offer and how they
are related.
If you have never used Python before, you should begin by reading Chapters
1–6 in order. If you already know Python, at least read the string policy (in
bullet points on page 28), and skim the material in Chapter 2 (apart from the
first section, which you’ll know well). Make sure that you are comfortable with
lambda and partial function application, both of which are covered in Chapter 2.
It is probably also worth skimming Chapter 3 as well. Then read Chapters 4,
5, and 6 in order.
Once you have covered the first six chapters, you have covered the essentials
of Python and the fundamentals of PyQt.
Chapter 7 is useful if you want to know how to create dialogs using a visual
design tool rather than purely by hand coding, something that can save a lot
of time. For file handling, at least read the first three sections of Chapter 8. If
you plan to write and read text files, also read Chapter 8’s fourth section, and
similarly the fifth section if you are going to use XML files.
For Part III, at the least read Chapter 10’s first section, on event handling, and
all of Chapter 11. Chapter 12 and the first section of Chapter 13 assume that
you have read about PyQt’s event handling, and that you have read Chapter 11.
Chapters 9 and 14 can be read stand-alone in this part, but Chapter 15 assumes
that you have read Chapter 14.
In Part IV, Chapter 16 assumes that you have read Chapters 14 and 15, but the
other chapters can be read independently.
If you find errors in the text or in the examples, or have other comments,
please write to mark@qtrac.eu quoting “PyQt book” in the subject line. The
book’s home page, where any corrections will be published, and from where the
examples and exercise solutions can be downloaded, is http://www.qtrac.eu/
pyqtbook.html.
If you want to participate in the PyQt community, it is worthwhile joining the
mailing list. Go to http://www.riverbankcomputing.com/mailman/listinfo/pyqt to
find a link to the archive, so that you can see what the mailing list is like, and
also for a form for joining. Python also has mailing lists and other community
activities. For these, go to http://www.python.org/community.

Acknowledgments

I have many people to thank, and I will begin with those who have been
intimately involved with the book.
Jasmin Blanchette is a senior software developer at Trolltech, a Qt expert, and
a fine editor and writer in his own right. I have cowritten two C++/Qt books
with him. Jasmin has made a huge number of suggestions and criticisms that
have immensely improved the quality of this book.
6 Introduction

David Boddie, Trolltech’s documentation manager, is an active PyQt open


source developer who has made many contributions to PyQt itself. His input
has helped ensure that I have covered everything necessary, and done so in a
sensible order.
Richard Chamberlain is cofounder and chief technology officer of Jadu Ltd., a
content management company. His feedback and insights have helped ensure
that the book is as broadly accessible as possible. He has also helped refine and
improve the code used in the examples and exercises.
Trenton Schulz is a Trolltech developer who has been a valuable reviewer of
my previous books. For this book, he has brought his Python and Qt knowledge
to bear, giving considerable feedback on the manuscript. Along with Richard,
he also ensured that Mac OS X users were never forgotten. In addition, he
spotted many subtle errors that I had missed.
Phil Thompson is PyQt’s creator and maintainer. He has been supportive of
the book from the start, even adding features and improvements to PyQt as
a direct result of discussions we have had regarding the book. He has made
numerous suggestions for the book’s improvement, and corrected many
mistakes and misunderstandings.
Special thanks to Samuel Rolland, who let me loose on his Mac laptop, to install
PyQt, test the examples, and take screenshots.
Thanks are also due to Guido van Rossum, creator of Python, as well as to the
wider Python community who have contributed so much to make Python, and
especially its libraries, so useful and enjoyable to use.
Thanks also to Trolltech, for developing and maintaining Qt, and in particular
to the Trolltech developers both past and present, many of whom I have had
the pleasure of working with, and who ensure that Qt is the best cross-platform
GUI development framework in existence.
Particular thanks to Jeff Kingston, creator of the Lout typesetting language.
I use Lout for all my books and for most of my other writing projects. Over
the years, Jeff has made many improvements and added numerous features to
Lout in response to feedback from users, including many that I have asked for
myself. Thanks also to James Cloos who created the condensed version of the
DejaVu Sans Mono font (itself derived from Jim Lyles’ Vera font) from which
this book’s monospaced font is derived.
The publisher, in the person of Editor-in-Chief Karen Gettman, was supportive
of this book from the very beginning. And special thanks to my editor, Debra
Williams-Cauley, for her support, and for making the entire process as smooth
as possible. Thanks also to Lara Wysong who managed the production process
so well, and to the proofreader, Audrey Doyle, who did such fine work.
Last but not least, I want to acknowledge my wife, Andrea. Her love, loyalty,
and support always give me strength and hope.
Part I

Python Programming
Random documents with unrelated
content Scribd suggests to you:
If you have been thus far successful, go to the hat, and, calling
attention to the fact, drop the half-dollar into it; then, as if you imagined
some one was doubtful whether the coin was really in the hat, make
some remark to the effect that if they do not believe you dropped it you
will do so again, at the same moment thrusting your hand down to the
crown to take it in sight again.
At the moment the hand is in this position, carefully place the six half-
dollars on the bottom, and let one remain in the palm. Pick up one of
these six, and holding it high, let it drop, being careful, however, that it
does not hit the other five.
The coin in your hand you proceed to take from any unusual place
which may occur to you—the window curtain, portière, a gentleman’s
beard, or a lady’s coiffure, are those most naturally suggested. As soon
as you take a half-dollar from its hiding-place, you pretend to place it in
your left hand, and from there command it to pass to the hat, but in
reality you palm it in your right where it is ready for the next position
from which you desire to take it. Proceed in this way until you have
gathered in six half-dollars.
As these have been lying quietly in the hat during all this time, you have
no anxiety about sending them there, and must simply avoid going near
it while apparently filling it with the money. When the last silver piece
has been sent to its destination, request the audience to select some
one of its members to count the money in the hat, and see that none
has been lost in its flight hence. It will, of course, be found all right, and
great will be the curiosity to know how you placed it there; but do not
allow yourself to be influenced into trying it a second time, for with the
close watching you will undergo your secret will be discovered.

ANOTHER HAT TRICK.

The hat may well be called “inexhaustible,” for all manner of things may
be made to come from its prolific crown, and in such profusion, that a
receptacle of double its size would hardly contain them.
If two boys have learned the art of palming well, they may assist each
other, and, if at all ingenious, invent a variety of tricks for an evening’s
amusement.
The following is but a suggestion, which may be varied by different
materials:
Let them borrow from the audience two tall silk hats, and place them
upon chairs standing some distance from each other. Each having
provided himself with a small rubber ball—the one resembling the other
as nearly as possible—they are ready to proceed. The hats were of
course empty when passed to the stage, but as the first boy takes his
place, back of the chair which contains a hat, he should glance down
into it, and with surprise, draw out a ball which he has had concealed in
his right hand, show it to the audience and then pretend to put it in his
left hand, but instead palm it in the right; at the same time extending
his left toward his partner. The second boy stretches out his right arm as
if to receive the ball, and at the moment his hand touches the fingers of
No. 1, he lets that which he has been palming in his right hand slip
down to his fingers, as if he had just received it from his friend. Now,
pretending to change it to his left, he palms it, as No. 1 has done, and
finally drops his left hand, which is supposed to hold the ball, into the
hat in front of him, at the same time giving the side or crown a rap with
one of his fingers, to imitate the falling of the ball. This same thing may
be repeated indefinitely, until you have balls enough to stock the village.
When you see the audience is beginning to tire, let No. 1 say, “My hat is
empty; shall I help you count the balls in yours?” No. 2 nods assent, and
looks down, as if expecting the hat to be full. He must then pretend
great surprise, and taking up the hat must turn it upside down, gently
shake it—remembering it is borrowed—and with the audience wonder
what has become of all the balls.
Eggs, small lemons or oranges, little china dolls, and a number of small
toys may be substituted for the rubber balls above given.

THE PERAMBULATING EGG.

This trick is one of the easiest, while at the same time one of the most
pleasing, of the magician’s arts. In it an egg, apparently without any
impulse beyond that which resides within itself, travels over a hat, and
after reconnoitering it in its every nook and corner, passes gracefully
over to another, and commences its journey of discovery around the
second in much the same manner it has traversed the first.
Two hats are borrowed from the audience, and a dish of eggs is placed
upon the table by their side, when the performer requests the lady
stationed at the piano to give some music, and the exhibition
commences. The egg which is used is merely a shell, the inside having
been sucked or blown out through tiny holes made at either end. A
slender silken thread is tied to the upper button of the performer’s
waistcoat, while attached to the other end is a small piece of wax or
other sticky substance. Just before the performance commences, show
the dish of eggs, and then pass away from them and back of your
audience, to show that they (the eggs) are in no way attached to your
person.
As the music strikes up, walk to the table, take the shell from the dish,
making it appear that you had no choice, but took the first one you
chanced to touch, and place it inside the hat, at the same moment
pressing the bit of wax to its side.
As the egg is in the hat it is necessary for it to pass out upon the
outside surface. To do this the hat is slowly moved downward until the
egg is even with the brim; then by careful management and a little
practice, the effect is produced of the egg walking up the hat instead of
the hat being lowered to the egg. You may now take the egg in your
hand and, holding the hat with the crown upward in a horizontal
position, place it beneath the egg, and turn it slowly away from yourself.
The effect will be that the egg is traveling up hill. By placing the other
hat close to the one upon which you are performing, and slowly drawing
it under the egg, the latter will appear to pass over to the crown of the
second hat, and very much the same movements may be repeated on
this as on the first.

THE MAGIC DISPATCHER.

Borrow a quarter or half-dollar from your audience, and ask the owner
to place some mark upon it by which it may be identified. Wrap this in
the corner of a handkerchief, and give it to some one to hold. Next take
a ball of yarn, and having placed it in a tumbler, ask some other person
in your audience to hold his hand over the top of the tumbler in such a
way that the ball will be kept in place, and the yarn will run smoothly
through the fingers. Hold one end of the yarn some distance from the
tumbler, or near where the coin is held, and inform your audience that,
as your dispatcher is in good working order, you will proceed to send the
coin your friend has in his hand into the very center of the ball of yarn.
Take the opposite corner of the handkerchief from the one holding the
money in your right hand, and having counted one, two, three,
command the coin to pass, at the same instant snatching the
handkerchief from your friend’s hand. Next commence to unwind the
ball, being careful to keep some distance from the tumbler while so
doing.

As the yarn is nearing its end, the silver piece will drop upon the bottom
of the tumbler, and nothing is left for you to do but to request the owner
of it to step forward and see if it is the one he lent you.
In this, as in many of the tricks you have already learned, very little
preparation is required. First, a coin of the same denomination as the
one borrowed is sewed in a corner of the handkerchief. The ball is
wound upon a stick of a particular shape, which is drawn out when the
coin is to be substituted in its place. This stick should be about two and
a half inches long, one and a quarter inches wide, and an eighth of an
inch thick, rounded off at one end, and scraped until it is perfectly
smooth.
When winding your ball, be careful to have the rounded end of the stick
in the center of the ball, and the other end projecting slightly on one
side.
After you have procured your coin, palmed it, and given the
handkerchief containing the other into the hands of some person to
hold, go for your ball, which should be at some distance from your
audience, that you may have time to draw out the stick and insert the
coin in its place, while you are walking back to the table upon which is
your tumbler.
The trick is now done, but the audience must be kept ignorant of the
fact, while your conversation and subsequent acting should shroud it in
all the mystery possible.

THE TURKISH RING TRICK.

A few years ago I had the good fortune to see a famous magician
perform. Many and wonderful were the things he did, and at times it
seemed as if other than human skill must be aiding him in his craft.
Among others, he gave the following trick, which was as enthusiastically
applauded as many of the others. It had for me no element of
strangeness, as I was already initiated into its secret. Since it has ever
been a favorite in the little amateur performances we have from time to
time been in the habit of giving, I hope it may gain a wider popularity in
the larger circle of friends to whom I am about to disclose it.
To the public it appears as follows: A plain gold ring is borrowed, placed
in a handkerchief, and given to a person to hold. A small stick is held by
two others, in such a position that its center is hidden by the
handkerchief; each person holds an end. The magician commands the
ring to pass, at the same moment snatching the handkerchief, a corner
of which he has taken, away from the one holding it—when behold! the
ring, which a moment ago was in the spectator’s hand, is now whirling
around the stick, which it evidently has just reached.
It is performed as follows: When the ring is taken from its owner, it is
palmed, and not placed in the handkerchief, as one is led to suppose,
the handkerchief being supplied, as you probably have already guessed,
with a ring which is sewed in its end. In passing the stick to the holders,
you have simply to pass it through the right hand, in the center of which
your ring is palmed, and, of course, through the ring itself. Then,
holding it until it is hidden by the handkerchief, is not difficult to do.
When you first take up the stick, be sure and use your left hand, so that
you will have it ready to pass through your ring without any awkward or
suspicious movements. Finally, pulling the handkerchief suddenly and
quickly across the stick, causes the ring to whirl upon it very much as if
it had just dropped in its place. It is always well, when performing with
the handkerchief, to have a second and similar one in your pocket, to
show in case suspicion should be aroused concerning it.

HOW TO MELT AND RE-COIN A HALF-DOLLAR.


Supply your table with a candle in a light candlestick, and a glass of
water. When ready to perform, request some one of your audience to
lend you a half-dollar, suggesting at the same time, that a new bright
coin would best suit your purpose. Have it marked that the owner may
be sure of its identity.
If nothing but dull coins are to be found, have a small bottle of
ammonia at hand, and holding the piece in your hand, pour a few drops
of the liquid upon it; let it stand a few moments and then wipe with a
bit of cloth. Treat both sides in the same way, and brighten up the
edges in like manner. All this while you may be talking of this treatment,
as if it were intended to render the metal more fusible, but be careful
not to mention what the fluid is, or for what it is really intended. This
treatment is, of course, not necessary in the case of new coins, in which
case it can be omitted.
When the silver is bright, and presents the appearance of a new coin,
take it between the thumb and forefinger of your right hand, look at it
carefully, and then pretend to drop it into your left hand, but instead
palm it in your right.
Now continue to move your left hand as if working the coin around in it,
keeping up a continual flow of small talk during the whole performance.
The difficulty of melting silver, the amount of heat required, and the
comparative hardness of different metals, forming good subjects, with
which you will become familiar before your public exhibition.
To render the idea of palming an apparent impossibility, take up the
candle in your right hand. This will render the holding of the coin less
troublesome, and appear to your audience as a conclusive evidence that
the half-dollar is in your left hand.
After you have pretended to place the coin in your left hand, do not for
an instant forget to appear as if it really was there, and keep that hand
always in sight of your audience.
Having taken the lighted candle in your right, hold the left hand above
the flame, and move the fingers as if allowing the silver to pass down,
drop by drop, into the candle itself. If, just before this, previous to
taking the candle, you could catch up the glass for a drink and drop a
spoonful of water into the hollow of your left hand, the dropping of it
into the candle-flame would add to the impression of melting silver. You
can wet your hand slightly in many natural ways, as no one would
imagine the water had anything to do with the trick. Continue to
pretend to drop the silver, until it would naturally be gone; then, without
removing your hand, open it and announce that the half-dollar is
melted, and can be found in the candlestick; assuring the donor that he
need not be alarmed, as you can bring it out as it was before it went in,
if he will but have patience.
Put the candlestick down upon the table, and pretend to pick out bits of
silver from the various parts of it with the right hand, placing them as
they are gathered in the palm of the left hand. At a convenient moment,
when the right is exactly above the left hand, drop the half-dollar into it,
and the trick is done. But it would not do to let the audience know this,
so you must continue to work the left hand as if molding the coin in
shape, blowing with the mouth into the palm as if cooling the heated
mass; toss it from hand to hand as if to cool it more rapidly, and finally
return it to the spectator from whom it was borrowed.

BURNING THE CENTER FROM A HANDKERCHIEF.

The young performer will find but little difficulty in performing this
simple sleight-of-hand trick successfully. A lighted candle, a small stick,
or magic wand, and a piece of thin cambric or muslin about six inches
square, are the materials required.
Place the lighted candle on your table, and the wand on another table or
shelf some distance from the former with the bit of cambric behind it.
Now borrow of some lady present a handkerchief, a gentleman’s being
inconveniently large. Take the handkerchief by the center, pull it
carefully between the fingers and thumb of left hand, and advance
toward the candle.
Just as you are about to burn it, stop and say, as if in answer to some
remark overheard, “Oh, no, I have not changed the handkerchief. See!”
and at the same time allow another inspection of it.
Suggest now to its owner, if, in case her handkerchief is burned, she
would like it restored again to its proper condition; and, upon her
answering in the affirmative, announce the necessity of the magic wand
for that purpose. Walk to the spot where the wand is lying, and take it
up, managing to pick up at the same time between the left thumb and
forefinger the bit of cambric; the center of this piece should be pointed
outward so that it may be readily pulled out at the desired moment, the
remainder being neatly rolled up and palmed under the thumb. This
piece should have been rolled up with the central point slightly
projecting when first placed on the shelf, and the performer should
manage to turn his back toward the audience for a few moments when
taking up the wand.
Place the wand in one of your coat pockets as you advance toward your
candle, and again take the handkerchief, putting it this time into the left
hand, and pull up the small piece of material, completely hiding the
center of the real handkerchief between the second and third fingers
and the palm of the hand.
The portion of the cambric extending beyond the thumb and forefinger
may now be safely burned, and the audience may be sure the
handkerchief is burned, as you can make some display of rolling it up in
a ball, taking care, however, to separate the burned piece from the real
article. Now take the wand from the pocket, and at the same time
manage to drop the small semi-burned piece of muslin unperceived into
the pocket; touch the handkerchief with the wand, and, after some
magic word or words, return the handkerchief to the owner to be
examined, remarking that you hope not even an odor of smoke is
noticeable about it.
Whenever displaying feats in magic, it is better for the performer to go
forward among the audience if he has anything to show or have
examined, than to allow the latter to come to his portion of the room.
His table has often some things upon it which if seen near by would do
much toward dispelling the mystery connected with his works.
A wide space should be left between his table and the front row of
spectators, as he often has occasion to step between the two in some of
his feats.
The lights also should be judiciously arranged, so as not to shine too
directly upon his hands or person, or even upon his table. Always have
everything you can possibly need in some easily accessible place, and in
just the position most convenient to be taken.
Decide beforehand what tricks you will perform, and in just what order
they are to be given. Of course, all the materials are not to be spread on
the table at the commencement of the entertainment, as they would be
in the way, and confuse you in your first acts; but they should all be at
hand, and while articles are being examined which have passed through
the various vicissitudes in a former trick, you can utilize the time when
the attention is thus carried away from yourself to gather together and
properly place the materials for your next feat.
Never be induced to perform a trick a second time, unless nearly a
whole evening’s performance intervenes. Even then it is pretty sure to
be detected.

THE MAGIC ROPE.

Take a piece of clothes-line, six or seven yards long, and pass it among
your audience for inspection. While it is going its rounds, have your
hands securely tied with a handkerchief, which should be passed around
the wrists and knotted on one side.
When the rope is returned to you, drop one end between your arms, or
inside the handkerchief, and request some one to take both ends of the
rope and pull, to make sure your hands are firmly tied. It would now
seem impossible to get the rope off, unless the hands were untied or the
ends released. After two or three rapid motions, however, the rope
drops to the floor, while your hands remain tied as at first.
First, do not have your hands tied so tightly that you cannot move
them; this can be arranged by holding them slightly apart while they are
being tied. After the rope has been pulled by the holder, it is somewhat
relaxed; and then, by rubbing it between the wrists a loop may be
formed, into which the second finger may be slipped. The whole hand is
now readily thrust through, and only a jerk is necessary to send the
rope upon the floor. In performing this trick, work as quickly as possible,
that your movements may not be easily followed.

A CAMPING-OUT COOKING-STOVE.

Although the winter season is now well upon us, and its reigning king,
Jack Frost, jealous if we but mention the “camp-fire,” has covered its
very site with ice and snow, we need not fear incurring his displeasure
by the following exhibition.
Procure an old silk hat if possible, and pass it among your audience for
inspection. Have upon the stage, or at your end of the room, a table,
with a drawer open at the back. In this drawer have a small cake in the
tin in which it was baked. Let it be made in a patty-pan if convenient.
Beside this cake have a small tin cup, which will fit rather tightly into the
mouth of a china jar you have also provided. On the top of the table
have an unlighted candle, the jar, which should be porcelain if possible,
a basket containing a few eggs, a pitcher of water, some flour, and a box
marked sugar. The hat, after having been examined, is returned to you;
and the cake, along with the cup which is to receive the eggs and flour,
are put into it. This is effected as follows: Take the cake and cup in your
left hand, keeping it down behind the table, and your hat in the right
hand; bring the cake and cup up to the edge, and immediately cover it
with the hat, which you begin brushing with your right. Keep up a
running discourse all the time, so that the movement will seem natural,
and not be suspected. In a moment or two partly withdraw the left
hand, and grasping the brim of the hat, turn it upside down upon the
table. If the tin is not in a good position to catch the eggs and flour
which you are to drop into it, palm a penny and pretend to find it in the
hat, chiding your audience for carelessly overlooking it, remarking that
although a useful thing to have, it is not exactly a proper ingredient for
cake. Of course, while pretending to pick up the coin, you can arrange
the tin cup on top of your cake in the middle of the hat. Be sure that it
stands firm.
Now proceed to break one or more eggs, and drop the contents into the
hat, taking especial care that they drop into the cup. Next throw in a
spoonful of sugar, and then pour a few drops of water and one or two
spoonfuls of flour into the jar, and stir well with a spoon. Pour the
contents of the jar into the cup, and then, under pretense of draining
the last drop into the hat, force the jar down over the cup, and work it
around until the cup is well pushed up into the mouth of the jar. It is
needless to add that you must pretend all the while that you are
scraping or shaking out the mixture. The jar can now be taken out and
carelessly placed behind the sugar-pail or any other object, to prevent
the edge of the tin cup from being seen.
The trick is now completed, the only necessary thing to do is to keep up
the acting until the cake is supposed to be finished.
First, stir it well by moving the spoon around quite actively in the hat;
then light the candle, and, informing your audience that the cake is
ready for baking, take the hat in one hand and hold it over the candle
for a minute or two, occasionally glancing in to see if it is doing well.
In a short time announce that it is baked; and after blowing out the
candle, take the cake from the hat, turn it out upon a plate, and placing
a knife by its side, pass it to some one to cut, and politely request your
friends to try it, and judge upon the efficacy of your camp-stove. If the
hat was borrowed, return it with thanks to its owner, and congratulate
him upon having such a useful article always on hand.

NECESSITY OF A SOBER COUNTENANCE.

In most, in fact all, of these exhibitions, it is absolutely necessary that


one should keep a sober countenance while performing. No matter how
hard your audience laugh, do not allow the shadow of a smile to flit
across your face. If you do it will take away much of the effectiveness
and half the mystery, from whatever you are doing.
I once had a young friend, a quick bright boy, who was very successful
in palming, and in many of the other elements in sleight-of-hand tricks,
but he had a ridiculous and unconquerable habit of laughing whenever
his audience laughed, and, in fact, of sometimes anticipating the laugh,
and commencing before his friends saw anything worth laughing about.
He was of course not successful, and was never watched with as much
interest as his brother, who, although not as clever, was as sober as a
judge from the beginning to the end of the performance. No amount of
hilarity in the audience affected him in the least. If he found it was
impossible to make himself heard, he stood still and waited; but always
with the same quiet, calm countenance he would have worn had he
been walking up the aisle of a church. Learn to command your
countenance, as one of the most important requisites of a successful
magician.

THE GREAT CHINESE ROPE FEAT.

Many years ago this trick was exhibited in a show-window on Broadway,


but as probably most of the people who then saw it have long since
forgotten how it was performed, I give the following account:
Two ropes, each about three yards in length, are given to the audience
to examine, which of course are pronounced perfect; then they are
passed through the sleeves of a coat, in such a way as to suspend it;
the ends are then given to two boys to hold. The performer then places
his hand inside the coat, and having requested those who are holding
the ends of the rope to pull, the coat falls to the floor, having in some
mysterious manner worked off the ropes.

Of course, the whole secret of this trick depends upon the arrangement
of the ropes, which are of themselves perfect. After they have been
examined, and are returned to the performer, he pretends to measure
them, and while so doing manages to bend each rope double; that is,
he brings the two ends of each together; while still holding them he
contrives to slip a small elastic band over the center of one, and
bringing the middle of the other alongside of it, he slips the band over
both, thus tying them together, as shown in the illustration.

Now holding this juncture carelessly in his left hand, over which arm a
coil or two of the rope is thrown, he passes the ends marked A through
one sleeve of the coat, and the end marked B through the other, and
these are the ends he gives to the two persons to hold.
If he now slips off the rubber band, the coat will fall; but each person
will have both ends of the same rope in his hand, and the mystery
would be easily solved. To remedy this, however, the performer, under
pretense of making the trick still more difficult, takes an end from each
of the holders, and proceeds to tie a single loop, as seen in the
illustration, thus reversing the ends, which he then returns to them.
Of course, when the band is taken off, each person has but one end of
either rope in his hand.

TO PULL A STRING THROUGH A BUTTON-HOLE.

Tie together the ends of a piece of string about two feet long; pass it
thus tied through a button-hole of your coat. Hitch the two ends on your
thumbs, and catch up with each little finger the upper string on the
thumb of the opposite hand; then, stretching the hands apart, the string
will appear in a very complicated tangle. If the hold of the right thumb
and left little finger, or vice versâ, be then loosed, and the hands quickly
separated, the string will come away from, and appear as if it had
passed through, the outside edge of the button-hole.

TO UNITE A PARTED STRING.

Take a piece of string about four feet long; hold the ends, pointed
upward, between the first and second finger and thumb of the left hand,
and the first finger and thumb of the right hand, letting the remainder
of the string hang down in a loop. Now bring the right hand close to the
left, crossing at right angles that end of the cord held in the left hand,
and continue to pull until half the length of the string has passed the left
hand, at the same time slipping the third finger of the left hand between
the two parts of the string.
The first finger and thumb of the right hand should then seize the string
at a point just below the little finger of the left hand, the third finger of
that hand at the same time drawing back the string toward the palm of
the hand.
The part of the string now held horizontally between the two hands is
only the continuation of the end held in the left hand, though it will
appear to be the middle of the string.
This piece of the string some one of the audience should be invited to
cut, and thus apparently divide the string in halves, although in fact he
only cuts off two or three inches.
Place all the ends of the string between the teeth, withdraw the short
piece with the tongue, and show the remainder, apparently as the string
was at the commencement.
Of course, the string must not be measured, or the trick will be
detected.

―――――◀▶―――――
A MINERAL GARDEN.
Fill a clear glass jar—a fruit jar will answer the purpose—with sand, to
the depth of two or three inches; insert a few pieces of sulphate of iron,
sulphate of copper, and sulphate of aluminum, so that they will be
barely covered with the sand.
Now fill the jar to within about three inches of the top with a solution of
silicate of soda, commonly known as “water-glass,” which can be
procured at most large city drug stores. This should be diluted with
three times its bulk of water before it is poured in; and care should be
taken not to stir up the sand and disarrange the chemicals.
After standing about a week, the silicates of the various bases will
appear in a luxuriant and variously colored growth, resembling
vegetation.
Now the silicate solution may be displaced with clear water, which
should be poured in very carefully, so as not to break or disturb the
vegetation. This permanent miniature forest will be found to present a
very attractive appearance, and as no pruning or weeding are required,
the young gardener will probably feel that his trouble is well repaid. Its
development from day to day will be watched with interest by all the
members of the household, although it will be of especial value to the
invalid, to whom any new and interesting object to watch is a blessing
indeed.
Another pleasing and ingenious device I insert for the benefit of this
class of my readers, wishing, in the meantime, that it might be in my
power to make their in-door life so bright and full of interest, that they
would forget the more active sports of their sturdy brothers and sisters,
or at least cease to regret their enforced confinement. This little affair I
shall call

THE CRYSTAL VASE.


This sparkling ornament will almost make itself, so little trouble is
required.
You have only to half fill a tall glass tumbler with water, and put in half a
teacupful of table salt, then let it stand.
As the water dries out, put in a little more, adding salt also in due
proportion; and keep this up for five or six months.
By degrees an incrustation of crystals will fill the tumbler, and spread
gradually down the outside; extending and thickening till the whole
vessel is covered with an irregular glittering mass, which might well be
the work of the ice-sprites in the kingdom of Jack Frost.
As the crystals approach the bottom of the tumbler, the latter should be
set in a saucer; when the tiny stalactites have enveloped this also, the
vase is complete.
Should it be desired to enhance still further the decorative effect of this
by the use of color, a blue tint can be communicated by adding a little
indigo blueing to the salt and water. Should other colors be desired,
almost all of those employed in coloring alum crystals (see page 25)
may be used with equal success in this case. By adding different colors
at different times, a variegated effect may be produced.
The gradual growth of the crystals, and enlargement of the mass, is a
very interesting spectacle.

―――――◀▶―――――
THREE CHRISTMAS OR BIRTHDAY GIFTS.
When speaking of Christmas presents in an earlier portion of this book, I
unintentionally omitted three quite interesting and easily made puzzles,
which are always pleasing sources of amusement to the young folks,
and sure to while away many half-hours on stormy days. Such presents
are always valuable additions to the nursery closet, and in an indirect
way are as gratifying to mamma and nurse as to the little recipient
himself. The first of these is called the

OCTAGON PUZZLE.

This puzzle consists of twelve irregular pieces of stiff pasteboard or


wood, which are to be arranged in the form of an octagon.
Although these pieces can be cut from pasteboard, they are more
lasting, stronger, and better every way if made of wood. White holly,
such as is employed for brackets, is a nice material to use.
With a jig-saw cut four pieces in shape like that represented in Fig. 1,
four like Fig. 2, and four more like Fig. 3; rub the edges down with
sand-paper, and, if you like, paint each set a different color. When the
paint is dry, varnish them.
Pack them in a small pasteboard box, which you can neatly cover with
paper—any fancy color will do—and you will find your little brother or
sister will be as well pleased with them as with many toys which have
come direct from the store.
Another puzzle of the same character as this is

THE CROSS PUZZLE.

In this, as in the Octagon, the pieces composing the cross may be made
of pasteboard, but are better and stronger if made of the white holly or
other thin “bracket wood.”
Cut three pieces—with the jig-saw, of course—in shape like Fig. 1, one
piece like Fig. 2, and one like Fig. 3.
These pieces may be of any size, but relatively each one must
correspond with the sizes and shapes indicated in the diagram.
Paint as fancy may dictate, after smoothing the edges off with sand-
paper. Pack in a box treated like that used for the “Octagon Puzzle.”
The last of these interesting puzzles is known as the

SQUARE PUZZLE.

Of the pasteboard or white holly cut out eight squares of whatever size
desired; divide four of them into halves by cutting them from corner to
corner, so there are in all twelve pieces.
The puzzle is to form a square of these twelve pieces. The illustration
shows how this is done.
When these puzzles are given to the little folks, no “key” should
accompany them, but the children should try to put them together
without help. If, however, you find they begin to lose interest, show
them the first step, and encourage them to try to finish it by
themselves.
There are great differences in children in this respect; some persevering
and unwilling to be helped at all, while others become discouraged at
the smallest obstacles and refuse to try. The latter should be
encouraged by a little help, care being taken, however, that they do a
considerable portion of the work themselves.
No doubt this “indolence,” as it is sometimes erroneously called, is
generally due to a weak physical condition, rather than to inferior
mental powers. A child of this temperament, instead of being ridiculed
by his more vigorous companions, should be encouraged and stimulated
to action; and such games or puzzles as those contained in this book
are just the things to accomplish this end.

―――――◀▶―――――
A SIMPLE FOUNTAIN.
Take a bottle holding eight or ten ounces, and insert a tube in the cork.
A fine glass tube or even a pipe-stem will answer.
The tube should reach nearly but not quite to the bottom of the bottle,
and should fit air-tight in the cork.
Fill the bottle about three-fourths full of water, and blow with
considerable force down the tube. Upon removing the mouth, the water
will spurt out, forming a miniature fountain; which will continue to play
as long as any water remains in the bottle.

―――――◀▶―――――
THE FAN FROM NAGASAKI.
A few months ago, a friend who had been for several years a resident of
Japan, came home to America for a visit, and brought with her a bright
little son and daughter, neither of whom had ever set foot on our
American shores before. The children were delighted with their
American cousins; and evidently could not find words strong enough to
sound the praises of the new games and sports which they were
constantly learning.
Their lives had been spent with Chinese or Japanese nurses; and
although kind-hearted and devoted as my friend assured me these
people were, the little exiles must have had a sorry time of it in their
foreign play-room, when compared with our own boys and girls. The
respect and almost reverence with which they regarded Jack, the most
daring scapegrace in our family, would have been very amusing had it
not been pathetic. What Jack did was always marvelous in their eyes,
and into many an unsuspected trap they were beguiled by his
mischievous pranks. They were what most of you boys and girls would
call very green, when they first reached us, but under Jack’s tuition, I
fear that next winter—in fact, at the very time you are reading this—
perhaps they will be trying the same tricks upon their innocent Japanese
nurse that Jack tried upon them.
It will not be strange if that long-suffering personage does not in his
secret heart have less respect for this illustrious nation than he has been
wont to have before.
But if so ignorant in most things, these children were very ingenious and
uncommonly happy in making things of paper.
One rainy morning, about a week after they came to us, I had occasion
to go into the nursery for something, and was quite surprised to find the
children busily engaged in folding paper. Edith had brought down some
rice-paper from her trunk, and with the help of her brother, was
fashioning all sorts of odd things from it; while the younger members of
my own family were looking on with intense interest.
I left the room, after watching them for a few minutes, but an hour
later, upon entering it again, found them still employed in the same
amusement.
It seems that their nurse had been in the habit of teaching them many
Japanese arts to keep them still while under his charge. Their nurse was
a man, strange to say, as very few female servants are employed in
either China or Japan, and now they in their turn were teaching these to
us. I confess the graceful, pretty things they were making had quite a
fascination for me, and I even left off what I had been doing, and
became a pupil with the youngsters. I took up the article which they
were just beginning to learn, and, following my little teacher’s directions,
I made what I have styled “The Fan from Nagasaki,” because my little
instructress was born and lived in that city, and learned her art from a
native Jap, and not because the fan itself, if it can strictly be called a
fan, came from that region.
The children called it by a delightfully odd Japanese name, which you
would find it hard to pronounce even if I should invent a way of spelling
it.
Edith used Japanese or rice paper for those she made; but we found a
stout quality of brown wrapping-paper, not too stiff, answers nearly as
well.
If brown paper is used, a rectangular piece about two feet long, by one
and a half feet wide, is a good-shaped piece to use.
Mark off each of the edges which measure eighteen inches into six
equal parts, each division being of course three inches long (see Fig. 1).
Now double the paper on the line at x, and you have a shape like Fig. 2.
Fold the uppermost half under at the line a a, and again outward at the
line b b; then fold the under half in precisely the same manner, and your
paper is like Fig. 3.
Upon examining the edge a a a, two openings between the folds will be
seen; whereas at the edge b b b, three openings will be found. The
hand has next to be placed in the middle of these three openings, and
the paper spread out toward the right and toward the left; that middle
fold lying flat or unfolded for the time being. Another figure is now
made like Fig. 4. Now commencing at one end of this long strip, crinkle
it the whole length as you would a lamplighter top, making the folds
even, about a quarter or half an inch wide. Be careful not to make these
folds wider than this, as the fan does not work as well when they are
wide. Yon have now a figure like that seen in Fig. 5; and if your folds
have been carefully and firmly creased, your paper is prepared to make
all sorts of strange shapes. I think Edith told me her nurse could make
sixty-five different forms from a similarly folded bit, and most of these
she was able to reproduce; but as it is some time since the children left
us to visit other friends, and I have not given the subject a second
thought till now, I find I have forgotten how many of the more intricate
ones were formed. Perhaps with the directions for these my readers will
catch the knack, as we Yankees call it, and can improvise some forms
unlike any of these, for themselves. Whatever you succeed in making,
you may be quite certain that the Nagasakian nurse, away off on the
other side of the earth, is ahead of you, and has made the same form
before; for his sixty-five must include about everything one could
possibly fashion from its folds.
In Fig. 6, the lower edge of Fig. 5 is held between the thumb and
forefinger of the left hand, while the top is spread out like a fan. For Fig.
7, take Fig. 6, insert the fingers at a, and pass them round to b, raising
the paper outward. Fig. 8 is a continuation of 6 and 7, as the upper
layer of the overhanging edge in Fig. 7 is raised by passing the finger
under it at c, and bringing it out at d.
Fig. 9 is a reverse of Fig. 8. Catch the paper by the part now uppermost,
pinch that part well together, and loosen the part which was confined in
Fig. 8.

It must be remembered that every time the fan is changed, the paper
must be pinched into its original form, Fig. 5. It will now be necessary to
make that change. After creasing the folds firmly in place (Fig. 5), lift up
the upper part a, bring the lower plaits b well together, and hold them
for the handle. With the disengaged hand, arrange the upper part in the
form of a sunshade. Another form may be got by raising the upper layer
of the sunshade cover, a species of cup or goblet. By drawing out b until
it is at right angles with the upright, the goblet form is nearer correct.
Now reverse the paper, and spread out the lower part so that it may
represent the body of a wine-glass; that which in Fig. 10 was the top of
the sunshade, is now the foot of the glass, as seen in Fig. 11.
The Chinese lantern (Fig. 12) is as easily made. Open out all the paper,
and twist it around; catch it now by the central part, and by
compressing the central folds well together, these wheels are produced
(Fig. 13).
The hat, or cup and saucer (Fig. 14), is readily made by opening the
paper out again, and catching it at the two ends.
We now come to a new form of subjects, so the original form (Fig. 5),
must once more be reverted to. If the paper is caught at both ends, it
can easily be folded so as to form Fig. 15, and a table-mat may be made
by drawing it out like Fig. 16.
A “nappie” dish, oval in form, and resembling Fig. 17, may be made
from Fig. 16, by simply raising up the sides a and b. By pressing the
paper inward, Fig. 18 is obtained. Fig. 19 is made by drawing the paper
out again, and letting it loose at the end. Thus you see, by pulling out
some parts and drawing in others, a quantity of things could be made
other than these I have shown. It would be quite interesting if every
boy and girl who reads this, would try on some rainy day to see how
near to the sixty-five he or she could come. If two or three friends in the
same neighborhood should unite their forces, and count all which are
unlike, without reference to the maker, they might not fall so far short of
the illustrious Japanese—I wish I could remember his name—after all.

―――――◀▶―――――
THE MINIATURE YACHT AND HOW TO RIG HER.
Boat making and sailing are most fascinating pursuits, and we do not
know but the old saying, “When a man has taken to boat-sailing, he is a
sailor to the end of his days,” is to a certain degree applicable to the boy
who intelligently fits out his tiny craft, and sends her on little voyages
across the neighboring pond.
If the sailing is to be done on water of any depth, there is one caution
we should like to give at the very outset: Learn to swim before you sail
her. No mere pleasure is worth risking one’s life for, and accidents will
happen even to the most careful boys.
After this, you may play on or near the water with as much safety as on
the land.
Aside from the pleasure, one learns an extremely useful lesson in
making a miniature model yacht, and in sailing her. A certain familiarity
with the rigging, and the looks of the thing, will thus be obtained, and if
your fingers have patiently set up shrouds and stays, and rove the
mimic halyards, they will be less at sea with the ropes and stays of a
real vessel.
Many boys living near the sea, and accustomed every day to see vessels
lying at anchor, or sailing in and out of the harbor, have very hazy ideas
concerning the rigging of any kind of craft. Well I remember in my early
days of being obliged to run down to the wharf to see where to attach
my topmast. Whether it belonged forward or aft of my mast I had not
the slightest remembrance, and yet scarcely a day went by without my
seeing a vessel in some form or other.
Boys are not the only persons, however, who look at things and do not
see them. The power of minute and careful observation is a rare quality,
and the majority of people go through life without forming the habit, or
indeed dreaming they have not made the best use of their sight.
For the benefit of the boys who belong to this class, and those less
fortunate ones living inland where yachts are unknown, I write this
chapter.
In several of our large cities, ponds are set apart for the especial
purpose of sailing toy vessels. They are the exclusive property of the
boys, and any fine afternoon in season, and frequently out of season, if
the ice does not interfere, crowds of boys may be seen sitting on the
edges of these “lakes,” intently watching the graceful fleet as it skims
lightly over the water. The sixty-acre lake in Prospect Park, Brooklyn,
and Conservatory Lake, Central Park, New York, are both set apart for
the owners of these miniature yachts; and it is wonderful how many
older people, as well as the boys themselves, take interest in this
amusement.
a Keel.
b Bowsprit.
c Stern.
d Mast.
e Topmast.
f Boom.
g Gaff.
h Forestay.
i Shrouds.
j Jib-stay.
k Topmast-stay.
l Topping lift.
m Main-sheet.
n Ensign.
o Throat halyards.
p Peak halyards.
q Burgee.
r Reef points.

The building and sailing of tiny yachts is carried to a much greater


extent in England than in this country. There the Prince of Wales is
deeply interested in the sport, and has instituted a “Royal Yacht
Club,” presided over by himself, which has regular yacht regattas.
These regattas take place on Serpentine Lake, in Hyde Park, every
summer, and are considered quite important events. The yachts
belonging to this club are very elegant affairs, one of them being
valued at $5,000, yet none of them are over five feet in length.
We do not expect our boy readers to emulate their British cousins,
but with the following simple directions we feel confident they can,
with a fair amount of skill in the use of tools, and careful labor, make
a very respectable miniature yacht, which shall be correct as far as
she goes in both form and rigging.
In the fashioning of a miniature boat, the hull is the first thing which
claims our attention; and in making this, two elements are to be
considered, rapidity and stability.
The rapidity or ease with which a vessel moves through water, is
gained by a narrow hull—that is, narrow in proportion to its length—
which, to be sure, renders the vessel somewhat unstable; but this
instability may be overcome by loading the keel with lead. There is
danger, however, of carrying this to too great an extent, by lowering
the vessel so much that the friction against her sides more than
counteracts the fine proportions of her build. Hence a skillful
designer reconciles these two points.
There are two types of model recognized in yacht building: First, the
English cutter model, which is narrow, and quite deep in proportion
to width, with its keel heavily weighted to secure the necessary
stability. This model is best adapted to rough cruising in strong
winds and heavy seas, such as prevail on the English coasts.
Second, the American: This, our model, is much wider, or, in nautical
phrase, has much more beam in proportion to length and depth.
Indeed, it is often so shallow as to merit the term “skimming-dish,”
ofttimes applied to this class of vessels.
These boats are usually fitted with center-boards, which can be
lowered or raised according to the need of the moment, instead of
the deep keel of the English model, American vessels having the
advantage of smoother water in which to make their cruises. The
sheltered surface of Long Island Sound and the bays which adjoin it
at either end, afford excellent sailing grounds for those owned in
New York and the vicinity.
For the toy boats our boys may desire to make, a medium between
these two types will probably be found preferable in practice.
The center-board may be ruled out at once, as both itself and the
well in which it plays would require more time and patience in their
construction than most boys would care to give.
It is much better to have your boat too wide than too narrow, as a
capsize is far more disconcerting to the average young yachtsman,
than a slight inferiority of speed.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like