You are on page 1of 53

Python GUI Programming Cookbook

Burkhard A. Meier
Visit to download the full and correct content document:
https://textbookfull.com/product/python-gui-programming-cookbook-burkhard-a-meier/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Python GUI Programming Cookbook Meier

https://textbookfull.com/product/python-gui-programming-cookbook-
meier/

Python Network Programming Cookbook Kathiravelu

https://textbookfull.com/product/python-network-programming-
cookbook-kathiravelu/

An Introduction to C GUI Programming Simon Long

https://textbookfull.com/product/an-introduction-to-c-gui-
programming-simon-long/

Beginning PyQt A Hands on Approach to GUI Programming


Willman Joshua M

https://textbookfull.com/product/beginning-pyqt-a-hands-on-
approach-to-gui-programming-willman-joshua-m/
Beginning PyQt A Hands on Approach to GUI Programming
Willman Joshua M

https://textbookfull.com/product/beginning-pyqt-a-hands-on-
approach-to-gui-programming-willman-joshua-m-2/

Create GUI Applications with Python Qt5 PySide2 Edition


Martin Fitzpatrick

https://textbookfull.com/product/create-gui-applications-with-
python-qt5-pyside2-edition-martin-fitzpatrick/

Create Gui Applications with Python Qt5 4th Edition


Martin Fitzpack

https://textbookfull.com/product/create-gui-applications-with-
python-qt5-4th-edition-martin-fitzpack/

Beginning PyQt: A Hands-on Approach to GUI Programming


1st Edition Joshua Willman

https://textbookfull.com/product/beginning-pyqt-a-hands-on-
approach-to-gui-programming-1st-edition-joshua-willman/

Foundations of PyGTK Development: GUI Creation with


Python W. David Ashley

https://textbookfull.com/product/foundations-of-pygtk-
development-gui-creation-with-python-w-david-ashley/
Python GUI Programming
Cookbook
Second Edition

Develop beautiful and powerful GUIs using the Python


programming language

Burkhard A. Meier

BIRMINGHAM - MUMBAI
Python GUI Programming Cookbook
Second Edition
Copyright © 2017 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its
dealers and distributors will be held liable for any damages caused or alleged to be caused
directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: November 2015

Second edition: May 2017

Production reference: 1190517

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78712-945-0

www.packtpub.com
Credits

Author Copy Editor


Burkhard A. Meier Muktikant Garimella

Reviewer Project Coordinator


Mohit Ulhas Kambali

Commissioning Editor Proofreader


Kunal Parikh Safis Editing

Acquisition Editor Indexer


Denim Pinto Aishwarya Gangawane

Content Development Editor Graphics


Anurag Ghogre Abhinash Sahu

Technical Editor Production Coordinator


Prashant Mishra Nilesh Mohite
About the Author
Burkhard A. Meier has more than 17 years of professional experience working in the
software industry as a software tester and developer, specializing in software test
automation development, execution, and analysis. He has a very strong background in
Python 3 software test automation development, as well as in SQL relational database
administration, the development of stored procedures, and debugging code.

While experienced in Visual Studio .NET C#, Visual Test, TestComplete, and other testing
languages (such as C/C++), the main focus of the author over the past five years has been
developing test automation written in Python 3 to test the leading edge of FLIR ONE (now
in its third generation) infrared cameras for iPhone and Android smart phones and
handheld tablets, as well as assuring the quality of FLIR bolometer IR camera platforms.

Being highly appreciative of art, beauty, and programming, the author developed GUIs in
C# and Python to streamline everyday test automation tasks, enabling these automated tests
to run unattended for weeks, collecting very useful data to be analyzed, automatically
plotted in graphs, and e-mailed to upper management upon completion of nightly
automated test runs.

His previous jobs include working as a senior test automation engineer and designer for
InfoGenesis (now Agilysys), QAD, InTouch Health, and FLIR Systems.

You can get in touch with him through his LinkedIn account, https://www.linkedin.com
/pub/burkhard-meier/5/246/296.

I would like to thank all truly great artists, such as Leonardo da Vinci, Charles Baudelaire,
Edgar Allan Poe, and so many more for bringing the presence of beauty into our human
lives. This book is about creating very beautiful GUIs written in the Python programming
language, and it was inspired by these truly great artists.
I would like to thank all of the great people that made this book possible. Without any of
you, this book would only exist in my mind. I would like to especially thank all of my
editors at Packt Publishing: Sonali, Anurag, Prashant, Vivek, Arwa, Sumeet, Saurabh,
Pramod, Nikhil, and so many more. I would also like to thank all of the reviewers of the
code of this book. Without them, this book would be harder to read and apply to real-world
problems. Last but not least, I'd like to thank my wife, our daughter, and our parents for
the emotional support they provided so successfully during the writing of the second
edition of this book. I'd also like to give thanks to the creator of the very beautiful and
powerful programming language that Python truly is. Thank you Guido.
About the Reviewer
Mohit (mohitraj.cs@gmail.com) is a Python programmer with a keen interest in the field
of information security. He completed his bachelor’s in technology in computer science
from Kurukshetra University, Kurukshetra, and master’s in engineering (2012) in computer
science from Thapar University, Patiala. He is a C|EH, ECSA from EC-Council USA and
former IBMer. He has published several articles in national and international magazines. He
is the author of Python Penetration Testing Essentials and Python Penetration Testing for
Developers, also by Packt Publishing.
www.PacktPub.com
For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and
ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a
print book customer, you are entitled to a discount on the eBook copy. Get in touch with us
at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a
range of free newsletters and receive exclusive discounts and offers on Packt books and
eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt
books and video courses, as well as industry-leading tools to help you plan your personal
development and advance your career.

Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Customer Feedback
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial
process. To help us improve, please leave us an honest review on this book's Amazon page
at https://www.amazon.com/dp/1787129454.

If you'd like to join our team of regular reviewers, you can e-mail us at
customerreviews@packtpub.com. We award our regular reviewers with free eBooks and
videos in exchange for their valuable feedback. Help us be relentless in improving our
products!
Table of Contents
Preface 1
Chapter 1: Creating the GUI Form and Adding Widgets 7
Introduction 7
Creating our first Python GUI 9
Getting ready 9
How to do it… 10
How it works… 10
There's more… 11
Preventing the GUI from being resized 12
Getting ready 12
How to do it… 12
How it works… 13
Adding a label to the GUI form 14
Getting ready 14
How to do it… 14
How it works… 15
There's more… 16
Creating buttons and changing their text property 16
Getting ready 17
How to do it… 17
How it works… 18
There's more… 18
Text box widgets 19
Getting ready 19
How to do it… 19
How it works… 20
Setting the focus to a widget and disabling widgets 21
Getting ready 21
How to do it… 21
How it works… 23
There's more… 23
Combo box widgets 24
Getting ready 24
How to do it… 24
How it works… 25
There's more… 26
Creating a check button with different initial states 26
Getting ready 26
How to do it… 27
How it works… 28
Using radio button widgets 28
Getting ready 29
How to do it… 29
How it works… 30
There's more… 31
Using scrolled text widgets 31
Getting ready 31
How to do it… 32
How it works… 33
Adding several widgets in a loop 34
Getting ready 34
How to do it… 34
How it works… 35
There's more… 35
Chapter 2: Layout Management 36
Introduction 36
Arranging several labels within a label frame widget 38
Getting ready 38
How to do it… 38
How it works… 40
There's more… 41
Using padding to add space around widgets 41
Getting ready 41
How to do it… 41
How it works… 42
How widgets dynamically expand the GUI 44
Getting ready 45
How to do it… 45
How it works… 49
There's more… 49
Aligning the GUI widgets by embedding frames within frames 49
Getting ready 49
How to do it… 50

[ ii ]
How it works… 53
Creating menu bars 54
Getting ready 55
How to do it… 55
How it works… 61
There's more… 62
Creating tabbed widgets 62
Getting ready 62
How to do it… 63
How it works… 68
Using the grid layout manager 68
Getting ready… 68
How to do it… 68
How it works… 70
Chapter 3: Look and Feel Customization 71
Introduction 71
Creating message boxes – information, warning, and error 72
Getting ready 73
How to do it… 73
How it works… 75
How to create independent message boxes 77
Getting ready 77
How to do it… 77
How it works… 80
How to create the title of a tkinter window form 81
Getting ready 81
How to do it… 81
How it works… 81
Changing the icon of the main root window 82
Getting ready 82
How to do it… 82
How it works… 83
Using a spin box control 83
Getting ready 83
How to do it... 83
How it works… 87
Relief, sunken and raised appearance of widgets 87
Getting ready 87
How to do it… 88

[ iii ]
How it works… 89
Creating tooltips using Python 90
Getting ready 90
How to do it… 91
How it works… 93
Adding a progressbar to the GUI 94
Getting ready 94
How to do it… 95
How it works… 97
How to use the canvas widget 97
Getting ready 97
How to do it… 98
How it works… 98
Chapter 4: Data and Classes 100
Introduction 100
How to use StringVar() 102
Getting ready 102
How to do it… 103
How it works… 105
How to get data from a widget 108
Getting ready 108
How to do it… 108
How it works… 109
Using module-level global variables 110
Getting ready 110
How to do it… 110
How it works… 111
How coding in classes can improve the GUI 114
Getting ready 115
How to do it… 115
How it works… 120
Writing callback functions 120
Getting ready 121
How to do it… 121
How it works… 121
Creating reusable GUI components 122
Getting ready 122
How to do it… 122
How it works… 126

[ iv ]
Chapter 5: Matplotlib Charts 127
Introduction 127
Creating beautiful charts using Matplotlib 128
Getting ready 128
How to do it… 129
How it works… 131
Installing Matplotlib using pip with whl extension 131
Getting ready 131
How to do it… 134
How it works… 137
Creating our first chart 138
Getting ready 138
How to do it… 138
How it works… 139
Placing labels on charts 140
Getting ready 140
How to do it... 140
How it works… 145
How to give the chart a legend 146
Getting ready 146
How to do it… 146
How it works… 149
Scaling charts 149
Getting ready 150
How to do it… 150
How it works… 151
Adjusting the scale of charts dynamically 152
Getting ready 152
How to do it… 152
How it works… 156
Chapter 6: Threads and Networking 157
Introduction 157
How to create multiple threads 159
Getting ready 160
How to do it… 160
How it works… 163
Starting a thread 163
Getting ready 163

[v]
How to do it… 165
How it works… 168
Stopping a thread 169
Getting ready 169
How to do it… 169
How it works… 172
How to use queues 173
Getting ready 173
How to do it… 174
How it works… 179
Passing queues among different modules 179
Getting ready 180
How to do it… 180
How it works… 182
Using dialog widgets to copy files to your network 183
Getting ready 183
How to do it… 183
How it works… 193
Using TCP/IP to communicate via networks 194
Getting ready 194
How to do it… 194
How it works… 197
Using urlopen to read data from websites 197
Getting ready 197
How to do it… 197
How it works… 201
Chapter 7: Storing Data in our MySQL Database via our GUI 202
Introduction 202
Installing and connecting to a MySQL server from Python 204
Getting ready 204
How to do it… 207
How it works… 210
Configuring the MySQL database connection 210
Getting ready 211
How to do it… 211
How it works… 214
Designing the Python GUI database 215
Getting ready 215
How to do it… 215

[ vi ]
How it works… 222
Using the SQL INSERT command 222
Getting ready 223
How to do it… 223
How it works… 225
Using the SQL UPDATE command 225
Getting ready 226
How to do it… 226
How it works… 230
Using the SQL DELETE command 231
Getting ready 231
How to do it… 231
How it works… 235
Storing and retrieving data from our MySQL database 235
Getting ready 235
How to do it… 235
How it works… 239
Using the MySQL workbench 239
Getting ready 240
How to do it… 240
How it works… 246
There's more… 246
Chapter 8: Internationalization and Testing 247
Introduction 247
Displaying widget text in different languages 249
Getting ready 249
How to do it… 249
How it works… 251
Changing the entire GUI language, all at once 252
Getting ready 252
How to do it… 252
How it works… 257
Localizing the GUI 257
Getting ready 258
How to do it… 258
How it works… 262
Preparing the GUI for internationalization 263
Getting ready 263
How to do it… 263

[ vii ]
How it works… 267
How to design a GUI in an agile fashion 267
Getting ready 268
How to do it… 268
How it works… 271
Do we need to test the GUI code? 271
Getting ready 272
How to do it… 272
How it works… 275
Setting debug watches 275
Getting ready 276
How to do it… 276
How it works… 280
Configuring different debug output levels 280
Getting ready 280
How to do it… 281
How it works… 283
Creating self-testing code using Python's __main__ section 284
Getting ready 284
How to do it… 284
How it works… 289
Creating robust GUIs using unit tests 289
Getting ready 289
How to do it… 289
How it works… 293
How to write unit tests using the Eclipse PyDev IDE 293
Getting ready 294
How to do it… 294
How it works… 300
Chapter 9: Extending Our GUI with the wxPython Library 301
Introduction 301
Installing the wxPython library 303
Getting ready 303
How to do it… 303
How it works… 306
Creating our GUI in wxPython 306
Getting ready 307
How to do it… 307
How it works… 311

[ viii ]
Quickly adding controls using wxPython 312
Getting ready 312
How to do it… 312
How it works… 317
Trying to embed a main wxPython app in a main tkinter app 318
Getting ready 318
How to do it… 319
How it works… 320
Trying to embed our tkinter GUI code into wxPython 321
Getting ready 321
How to do it… 321
How it works… 323
Using Python to control two different GUI frameworks 324
Getting ready 324
How to do it… 324
How it works… 326
Communicating between the two connected GUIs 327
Getting ready 328
How to do it… 328
How it works… 332
Chapter 10: Creating Amazing 3D GUIs with PyOpenGL and PyGLet 333
Introduction 333
PyOpenGL transforms our GUI 335
Getting ready 335
How to do it… 336
How it works… 339
Our GUI in 3D! 339
Getting ready 340
How to do it… 340
How it works… 344
Using bitmaps to make our GUI pretty 345
Getting ready 345
How to do it… 346
How it works… 348
PyGLet transforms our GUI easier than PyOpenGL 348
How to do it… 349
How it works… 351
Our GUI in amazing colors 351
Getting ready 352

[ ix ]
How to do it… 352
How it works… 355
OpenGL animation 355
Getting ready 356
How to do it… 356
How it works… 362
Creating a slide show using tkinter 362
Getting ready 363
How to do it… 363
How it works… 368
Chapter 11: Best Practices 369
Introduction 369
Avoiding spaghetti code 370
Getting ready 371
How to do it… 371
How it works… 374
Using __init__ to connect modules 377
Getting ready 378
How to do it… 378
How it works… 383
Mixing fall-down and OOP coding 384
Getting ready 384
How to do it… 384
How it works… 388
Using a code naming convention 388
Getting ready 389
How to do it… 389
How it works… 391
When not to use OOP 392
Getting ready 392
How to do it… 392
How it works… 396
How to use design patterns successfully 396
Getting ready 396
How to do it… 396
How it works… 399
Avoiding complexity 399
Getting ready 399
How to do it… 400

[x]
How it works… 404
GUI design using multiple notebooks 405
Getting ready 405
How to do it… 405
How it works… 409
Index 413

[ xi ]
Preface
In the second edition of this book, we will explore the beautiful world of graphical user
interfaces (GUIs) using the Python programming language. We will be using the latest
version of Python 3. All of the recipes from the First Edition are included in this edition. We
have added a few new recipes to the Second Edition, which you might not easily find via a
Google search. I think these new recipes will be useful and interesting to the reader.

This is a programming cookbook. Every chapter is self-contained and explains a certain


programming solution. We will start very simply, yet throughout this book we will build a
working application written in Python 3. Each recipe will extend building this application.
Along the way, we will talk to networks, queues, databases, the OpenGL graphical library,
and many more technologies. We will apply design patterns and use best practices.

The book assumes that the reader has some experience using the Python programming
language, but that is not really required to successfully use this book. This book can also be
used as an introduction to the Python programming language, if, and only if, you are
dedicated in your desire to become a Pythonic programmer.

If you are an experienced developer in any other language, you will have a fun time
extending your professional toolbox by adding writing GUIs using Python to your toolbox.
Are you ready?

Let's start on our journey…

What this book covers


Chapter 1, Creating the GUI Form and Adding Widgets, explains how to develop our first GUI
in Python. We will start with the minimum code required to build a running GUI
application. Each recipe then adds different widgets to the GUI form.

Chapter 2, Layout Management, explores how to arrange widgets to create our Python GUI.
The grid layout manager is one of the most important layout tools built into tkinter that we
will be using.

Chapter 3, Look and Feel Customization, shows several examples of how to create a good look
and feel GUI. On a practical level, we will add functionality to the Help | About menu item
we created in one of the recipes.
Preface

Chapter 4, Data and Classes, discusses saving the data our GUI displays. We will start using
object-oriented programming (OOP) in order to extend Python's built-in functionality.

Chapter 5, Matplotlib Charts, explains how to create beautiful charts that visually represent
data. Depending upon the format of the data source, we can plot one or several columns of
data within the same chart.

Chapter 6, Threads and Networking, explains how to extend the functionality of our Python
GUI using threads, queues, and network connections. This will show us that our GUI is not
limited at all to the local scope of our PC.

Chapter 7, Storing Data in Our MySQL Database via Our GUI, shows us how to connect to a
MySQL database server. The first recipe in this chapter will show how to install the free
MySQL Server Community Edition, and in the following recipes we will create databases,
tables, and then load data into those tables as well as modify these data. We will also read
the data back out from the MySQL server into our GUI.

Chapter 8, Internationalization and Testing, shows how to internationalize our GUI by


displaying text on labels, buttons, tabs, and other widgets in different languages. We will
start simple and then explore how we can prepare our GUI for internationalization at the
design level. We will also explore several ways to automatically test our GUI using Python's
built-in unit testing framework.

Chapter 9, Extending Our GUI with the wxPython Library, introduces another Python GUI
toolkit that currently does not ship with Python. It is called wxPython, and we will be using
the Phoenix version of wxPython, which was designed to work well with Python 3.

Chapter 10, Creating Amazing 3D GUIs with PyOpenGL and PyGLet, shows how to transform
our GUI by giving it true three-dimensional capabilities. We will use two Python third-
party packages. PyOpenGL is a Python binding to the OpenGL standard, which is a
graphics library that comes built-in with all major operating systems. This gives the
resulting widgets a native look and feel. PyGLet is another such binding that we will
explore in this chapter. We will also show some code that directly uses the PyOpenGL
library. This is a low-level approach that might open some doors for the interested reader.

Chapter 11, Best Practices, explores different best practices that can help us to build our GUI
in an efficient way and keep it both maintainable and extendible. Best practices are
applicable to any good code, and our GUI is no exception to designing and implementing
good software practices.

[2]
Preface

What you need for this book


All required software for this book is available online and is free of charge. This starts with
Python 3 itself, and then extends to Python's add-on modules. In order to download any
required software, you will need a working Internet connection.

Who this book is for


This book is for programmers who wish to create a GUI. You might be surprised by what
we can achieve by creating beautiful, functional, and powerful GUIs using the Python
programming language. Python is a wonderful, intuitive programming language, and is
very easy to learn.

I invite you to start on this journey now. It will be a lot of fun!

Conventions
In this book, you will find a number of styles of text that distinguish between different
kinds of information. Here are some examples of these styles, and an explanation of their
meaning.

Code words in text, database table names, folder names, filenames, file extensions,
pathnames, and user input are shown as follows: "Using Python, we can create our own
classes using the class keyword instead of the def keyword."

A block of code is set as follows:


import tkinter as tk
win = tk.Tk()
win.title("Python GUI")
win.mainloop()

Any command-line input or output is written as follows:


pip install numpy-1.9.2+mkl-cp36-none-win_amd64.whl

New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "Next, we will add
functionality to the menu items, for example, closing the main window by clicking the Exit
menu item and displaying a Help | About dialog."

[3]
Preface

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book-what you liked or disliked. Reader feedback is important for us as it helps us develop
titles that you will really get the most out of.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention the


book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.

Downloading the example code


You can download the example code files for this book from your account at http://www.p
acktpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.c
om/supportand register to have the files e-mailed directly to you.

You can download the code files by following these steps:

1. Log in or register to our website using your e-mail address and password.
2. Hover the mouse pointer on the SUPPORT tab at the top.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box.
5. Select the book for which you're looking to download the code files.

[4]
Preface

6. Choose from the drop-down menu where you purchased this book from.
7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the
latest version of:

WinRAR / 7-Zip for Windows


Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPubl
ishing/Python-GUI-Programming-Cookbook-Second-Edition. We also have other code
bundles from our rich catalog of books and videos available at https://github.com/Packt
Publishing/. Check them out!

Downloading the color images of this book


We also provide you with a PDF file that has color images of the screenshots/diagrams used
in this book. The color images will help you better understand the changes in the output.
You can download this file from
https://www.packtpub.com/sites/default/files/downloads/PythonGUIProgrammingCook
bookSecondEdition_ColorImages.pdf.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do
happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-
we would be grateful if you could report this to us. By doing so, you can save other readers
from frustration and help us improve subsequent versions of this book. If you find any
errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting
your book, clicking on the Errata Submission Form link, and entering the details of your
errata. Once your errata are verified, your submission will be accepted and the errata will
be uploaded to our website or added to any list of existing errata under the Errata section of
that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/conten


t/supportand enter the name of the book in the search field. The required information will
appear under the Errata section.

[5]
Preface

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At
Packt, we take the protection of our copyright and licenses very seriously. If you come
across any illegal copies of our works in any form on the Internet, please provide us with
the location address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated


material.

We appreciate your help in protecting our authors and our ability to bring you valuable
content.

Questions
If you have a problem with any aspect of this book, you can contact us
at questions@packtpub.com, and we will do our best to address the problem.

[6]
Creating the GUI Form and
1
Adding Widgets
In this chapter, we start creating amazing GUIs using Python 3.6 and above. We will cover
the following topics:

Creating our first Python GUI


Preventing the GUI from being resized
Adding a label to the GUI form
Creating buttons and changing their text property
Text box widgets
Setting the focus to a widget and disabling widgets
Combo box widgets
Creating a check button with different initial states
Using radio button widgets
Using scrolled text widgets
Adding several widgets in a loop

Introduction
In this chapter, we will develop our first GUI in Python. We will start with the minimum
code required to build a running GUI application. Each recipe then adds different widgets
to the GUI form.
Creating the GUI Form and Adding Widgets

In the first two recipes, we will show the entire code, consisting of only a few lines of code.
In the following recipes, we will only show the code to be added to the previous recipes.

By the end of this chapter, we will have created a working GUI application that consists of
labels, buttons, text boxes, combo boxes, check buttons in various states, as well as radio
buttons that change the background color of the GUI.

At the beginning of each chapter, I will show the Python modules that belong to each
chapter. I will then reference the different modules that belong to the code shown, studied
and run.

Here is the overview of Python modules (ending in a .py extension) for this chapter:

[8]
Creating the GUI Form and Adding Widgets

Creating our first Python GUI


Python is a very powerful programming language. It ships with the built-in tkinter
module. In only a few lines of code (four, to be precise) we can build our first Python GUI.

Getting ready
To follow this recipe, a working Python development environment is a prerequisite. The
IDLE GUI, which ships with Python, is enough to start. IDLE was built using tkinter!

All the recipes in this book were developed using Python 3.6 on
a Windows 10 64-bit OS. They have not been tested on any other
configuration. As Python is a cross-platform language, the code
from each recipe is expected to run everywhere.
If you are using a Mac, it does come with built-in Python, yet it
might be missing some modules such as tkinter, which we will
use throughout this book.
We are using Python 3.6, and the creator of Python intentionally
chose not to make it backwards compatible with Python 2. If
you are using a Mac or Python 2, you might have to install
Python 3.6 from www.python.org in order to successfully run the
recipes in this book.
If you really wish to run the code in this book on Python 2.7,
you will have to make some adjustments. For example, tkinter
in Python 2.x has an uppercase T. The Python 2.7 print
statement is a function in Python 3.6 and requires parentheses.
While the EOL (End Of Life) for the Python 2.x branch has been
extended to the year 2020, I would strongly recommend that
you start using Python 3.6 and above.
Why hold on to the past, unless you really have to?
Here is a link to the Python Enhancement Proposal (PEP) 373
that refers to the EOL of Python 2: https://www.python.org/d
ev/peps/pep-0373/

[9]
Another random document with
no related content on Scribd:
President in the Philippines sufficed fully, it was contended,
for every purpose of temporary or provisional government
there, except in its lack of ability to grant franchises and
to dispose of the public lands. Hence it was freely charged
that the controlling influences which pressed this measure on
the government came from capitalists and speculators who were
reaching after valuable franchises, mining rights and land
grants in the archipelago. Said Senator Daniel in the debate:
"So far as any legislation which looks forward to the opening
of the way to civil government may be involved to the
softening of the conditions which exist, to the amelioration
of the distresses which are upon the Philippine people, I
would give most cheerful acquiescence. But because we desire
to do these things in a good spirit, in a resolute and
patriotic spirit, let us not permit the provocation of
difficult conditions to lead us into enacting any kind of
provision of law that is not necessary to these ends. Let us
not undertake to give to the President of the United States
any power of disposing of the permanent assets of the
Philippine people; let us not put him in the attitude of being
a franchise giver or a franchise seller or a franchise lessor.
The franchises of those islands—their rivers, their ferries,
their streets, their roads, the thousand and one privileges
which are granted by public authority—are as important and as
valuable to that people and as permanently associated with
their happiness and their prosperity as are their fields or
their mines or their fisheries or anything else which belongs
to their country. … It is true there is the reservation of the
right to alter, amend, or repeal, but while that is legally
broad enough for any remedial legislation whatsoever to
follow, we know that practically it is of very small
consequence. If capital goes in and invests itself in
improvements which are in themselves of a permanent nature, if
railroads are constructed, telegraph lines run, telephones
established, ferries built, steamers and boats, gas
establishments, electrical establishments—if those things are
disposed of, the man who once gets in will never be gotten
out. In all such affairs possession is nine points of the law
before they get into court, where it is generally made the
tenth."

Senator Hoar called attention "to the fact that the report of
the Taft commission urges that power be given to sell the
public lands at once, as it is necessary for their
development, and a large amount of capital is there now
clamoring to be invested," and he remarked: "So I suppose that
one of the chief purposes of this is that the public lands in
the Philippine Islands may be sold before the people of the
islands have any chance whatever to have a voice in their
sale." He then quoted the following passages from the report
of the Taft commission:

"The commission has received a sufficient number of


applications for the purchase of public land to know that
large amounts of American capital are only awaiting the
opportunity to invest in the rich agricultural field which may
here be developed. In view of the decision that the military
government has no power to part with the public land belonging
to the United States, and that the power rests alone in
Congress, it becomes very essential, to assist the development
of these islands and their prosperity, that Congressional
authority be vested in the government of the islands to adopt
a proper public-land system, and to sell the land upon proper
terms. There should, of course, be restrictions preventing the
acquisition of too large quantities by any individual or
corporation, but those restrictions should only be imposed
after giving due weight to the circumstances that capital can
not be secured for the development of the islands unless the
investment may be sufficiently great to justify the
expenditure of large amounts for expensive machinery and
equipments.
{401}
Especially is this true in the cultivation of sugar land. …
Restricted powers of a military government referred to in
discussing the public lands are also painfully apparent in
respect to mining claims and the organization of railroad,
banking, and other corporations, and the granting of
franchises generally. It is necessary that there be some body
or officer vested with legislative authority to pass laws
which shall afford opportunity to capital to make investment
here. This is the true and most lasting method of
pacification." "In other words," said Senator Hoar, "the
leading, principal, bald proposal on which this amendment
rests is that before those 10,000,000 people are allowed any
share in their own government whatever their property is to be
sold by Americans to Americans in large quantities, as on the
whole the best means of pacification—that the best way to
pacify a man is to have one foreign authority to sell his
property and another to buy it." An amendment to the
amendment, offered by Senator Bacon, reserving to Congress the
right to annul any grant or concession made, or any law
enacted, by any governmental authority created under the
powers proposed to be conferred on the President; another
offered, by Senator Vest, providing that "no judgment, order,
nor act by any of said officials so appointed shall conflict
with the Constitution and laws of the United States," and
still others of somewhat kindred aims, were voted down; but
the influence of Senator Hoar prevailed with the Senate so far
as to induce its acceptance of the following important
modification of the so-called "Spooner Amendment":

"Provided, That no sale or lease or other disposition of the


public land, or the timber thereon, or the mining rights
therein, shall be made: And provided further, That no
franchise shall be granted which is not approved by the
President of the United States, and is not, in his judgment,
clearly necessary for the immediate government of the islands
and indispensable for the interests of the people thereof, and
which can not, without great public mischief, be postponed
until the establishment of a permanent civil government, and
all such franchises shall terminate one year after the
establishment of such civil government."

With this proviso added, the "Spooner amendment" was adopted


by the Senate on the 26th of February (yeas 45, nays 27, not
voting 16), and agreed to by the House on the 1st of March
(yeas 161, nays 136, not voting 56).

Congressional Record,
February 25-March 1, 1901.

PHILIPPINE ISLANDS: A. D. 1901 (March).


Organization of provincial governments.
Establishment of a department of public education.
Proposed tariff.
Date fixed for cessation of military regime.

On the 3d of March, the President of the Philippine


Commission, Judge Taft, addressed a cable despatch to the U.
S. Secretary of War in which he reported: "Commission has last
three weeks organized five provincial governments—Pampanga,
Pangasinan, Tarlac, Bulacan, Bataan—last two are Tagalog
provinces. Attended each provincial capital in a body; met by
appointment Presidentes, Councillors, and principal men of
towns; explained provisions general provincial act and special
bill for particular province and invited discussion natives
present of both bills. Conventions thus held very
satisfactory; amendments suggested, considered, special bills
enacted, appointments followed. … In three large provinces
natives appointed provisional Governors. In Bataan, on
petition, eight out of nine towns, volunteer officer
appointed. In Tarlac feeling between loyal factions required
appointment American. … In compliance with urgent native
invitations leave March 11 for south to organize provinces
Tayabas, Romblon, Iloilo, Capiz, Zamboanga, such others are
ready. Returning shall organize Zambales, Union, Cagayan,
Ilocos Norte. Military Governor has recommended organization
Batangas, Cavité, Laguna, Nueva Ecija, but shall delay action
as to these until return from northern and southern trips."

On the 18th of March it was announced from Washington that a


number of recent Acts of the Philippine Commission had been
received at the War Department, among them one which
establishes a general department of public instruction, with a
central office at Manila, under the direction of a general
superintendent, to be appointed by the commission, at a salary
of $6,000 a year. "Schools are to be established in every
pueblo in the archipelago where practicable, and those already
established shall be reorganized where necessary. There are to
be ten school divisions in the archipelago, each with a
division superintendent, and there is to be a superior
advisory board, composed of the general superintendent and
four members to be appointed by the Philippine Commission, to
consider the general subject of education in the islands and
make regulations. The English language, as soon as
practicable, shall be made the basis of all public
instruction, and soldiers may be detailed as instructors until
replaced by trained teachers. Authority is given to the general
superintendent to obtain from the United States 1,000 trained
teachers, at salaries of not less than $75 nor more than $100
a month, the exact salary to be fixed according to the
efficiency of the teacher. The act provides that no teacher or
other person "shall teach or criticise the doctrines of any
church, religious sect or denomination or shall attempt to
influence the pupils for or against any church or religious
sect in any public school." Violation of this section is made
punishable by summary dismissal from the public service. It is
provided, however, that it may be lawful for the priest or
minister of the pueblo where the school is situated to teach
religion for half an hour three times a week in the school
building to pupils whose parents desire it. But if any priest,
minister or religious teacher use this opportunity "for the
purpose of arousing disloyalty to the United States or of
discouraging the attendance of pupils or interfering with the
discipline of schools," the division superintendent may forbid
such offending priest from entering the school building
thereafter. The act also provides for a normal school at
Manila for the education of natives in the science of
teaching. It appropriates $400,000 for school buildings,
$220,000 for text books and other supplies for the current
calendar year, $25,000 for the normal school, $15,000 for the
organization and maintenance of a trade school in Manila and
the same amount for a school of agriculture.

{402}

The new tariff for the Islands, which the Commission had been
long engaged in framing, was submitted, in March, to the
government at Washington for approval. "In his letter of
transmittal Judge Taft says that the proposed bill follows
largely the classification of the Cuban tariff, 'but has been
considerably expanded by the introduction of articles
requiring special treatment here by reason of different
surroundings and greater distance from the markets.' Judge
Taft says also that the disposition of the business interests
of the islands is to accept any tariff the commission
proposes, provided only that the duties are specific and not
ad valorem. The question of revenue was kept steadily in view
in the preparation of the schedules, but it was not the only
consideration. Raw materials of Philippine industries, tools,
implements and machinery of production, materials of
transportation, the producers and transmitters of power and
food products are taxed as lightly as possible. … Export
duties are levied on only six articles—hemp, indigo, rice,
sugar, cocoanuts, fresh or as copra, and tobacco. The free
list admits natural mineral waters, trees, shoots and plants,
gold, copper and silver ores, fresh fruits, garden produce,
eggs, milk, ice and fresh meat, except poultry and game. There
is also a list of articles conditionally free of duty. The
importation of explosives is prohibited, but that of firearms
is not."
It is announced from Washington that "Judge Taft and General
MacArthur have agreed upon July 1 as the date for the
establishment of civil government in the Philippines. The
military regime in the islands will therefore cease on June
30, when General Chaffee will relieve General MacArthur of the
command, and Governor Taft will be inaugurated the next day
with considerable ceremony."

PHILIPPINE ISLANDS: A. D. 1901 (March-April).


Capture of Aguinaldo.
His oath of allegiance to the United States.
His address to his countrymen, counselling peace.

A stratagem, executed with great daring by General Funston of


the American forces, accomplished the capture of the Filipino
leader, Aguinaldo, on the 23d of March. From intercepted
correspondence, it had been learned that Aguinaldo, then
occupying his headquarters at Palanan, Isabela Province, was
expecting to be joined by some riflemen, whom his brother had
been ordered to send to him from central Luzon. On this,
General Funston conceived the plan of equipping a number of
native troops who should pass themselves off as the expected
reinforcements, several American officers going with them
ostensibly as prisoners, the hope being that Aguinaldo might
thus be reached and taken by surprise. General MacArthur
approved the scheme, and it was carried out with success. The
party was made up of 78 Macabebe scouts, four Tagalogs who had
formerly been officers in the insurgent army, and General
Funston, Captain Newton, Lieutenants Hazzard and Mitchel, who
acted the part of prisoners. They were taken by gunboat from
Cavite to a point above Baler, whence they made their way on
foot, sending a message in advance that the expected
reinforcements were on the way and had captured some prisoners
en route. The following brief narrative of what occurred
subsequently is taken from a newspaper account of the
expedition:
"For six days the expedition marched over an exceedingly
difficult country, covering 90 miles. When the men reached a
point eight miles from Aguinaldo's camp they were almost
exhausted from lack of food and the fatigue of the march. They
stopped at this place and sent a message to Aguinaldo,
requesting him to send food to them. The ruse thus far had
worked with the greatest success, and on March 22d, when
Aguinaldo sent provisions, it was seen that he did not have
the slightest suspicion. With the food he sent word that the
Americans were not wanted in his camp, but instructing their
supposed captors to treat them kindly. On March 23d the march
was resumed, the Macabebe officers starting an hour ahead of
the main body of the expedition. The 'prisoners,' under guard,
followed them. When the party arrived at Aguinaldo's camp a
bodyguard of 50 riflemen was paraded, and the officers were
received at Aguinaldo's house, which was situated on the
Palanan River. After some conversation with him, in which they
gave the alleged details of their suppositious engagement with
an American force, they made excuses and quietly left the
house. They at once gave orders in an undertone for the
Macabebes to get in position and fire on the bodyguard. The
order was obeyed with the greatest rapidity, and three volleys
were delivered. The insurgents were panic-stricken by the
sudden turn in affairs, and they broke and ran in
consternation. Two of them, however, were killed and eighteen
wounded. Simultaneously with the delivery of the volleys the
American officers rushed into Aguinaldo's house. Major
Alhambra, one of Aguinaldo's staff, had been shot in the face.
He, however, was determined not to be captured and he jumped
from a window into the river and disappeared. Two captains and
four lieutenants made their escape in a similar manner.
Aguinaldo, Colonel Villa, his chief of staff, and Santiago
Barcelona, the insurgent treasurer, did not have time to make
an attempt to get away before General Funston and the others
were upon them, demanding their surrender. Seeing that the
situation was hopeless, they gave themselves up. Aguinaldo was
furious at having been caught, but later he became
philosophical and declared that the ruse by which he had been
captured was the only one which would have proved successful
if the Americans had tried for 20 years. One of the Macabebes
was wounded. The party stayed two days at the camp and then
marched overland to the coast, where the Vicksburg, whose
arrival was excellently timed, picked them up and brought them
back to Manila."

On the 2d of April, a despatch from General MacArthur to the


War Department announced that Aguinaldo, on the advice of
Chief Justice Arellano, had taken the following oath of
allegiance to the United States: "I hereby renounce all
allegiance to any and all so-called revolutionary governments
in the Philippine Islands, and recognize and accept the
supreme authority of the United States of America therein; I
do solemnly swear that I will bear true faith and allegiance
to that government; that I will at all times conduct myself as
a faithful and law abiding citizen of the said islands, and
will not, either directly or indirectly, hold correspondence
with or give intelligence to an enemy of the United States,
nor will I abet, harbor or protect such enemy; that I impose
upon myself these voluntary obligations without any mental
reservations or purpose of evasion, so help me God."

{403}

On the 19th of April, Aguinaldo issued the following address


to his countrymen: "I believe I am not in error in presuming
that the unhappy fate to which my adverse fortune has led me
is not a surprise to those who have been familiar with the
progress of the war. The lessons taught with a full meaning,
and which have recently come to my knowledge, suggest with
irresistible force that a complete termination of hostilities
and lasting peace are not only desirable, but absolutely
essential to the welfare of the Philippine Islands. The
Filipinos have never been dismayed at their weakness, nor have
they faltered in following the path pointed out by their
fortitude and courage. The time has come, however, in which
they find their advance along this path to be impeded by an
irresistible force, which, while it restrains them, yet
enlightens their minds and opens to them another course,
presenting them the cause of peace. This cause has been
joyfully embraced by the majority of my fellow countrymen who
already have united around the glorious sovereign banner of
the United States. In this banner they repose their trust and
believe that under its protection the Filipino people will
attain all those promised liberties which they are beginning
to enjoy. The country has declared unmistakably in favor of
peace. So be it. There has been enough blood, enough tears and
enough desolation. This wish cannot be ignored by the men
still in arms, if they are animated by a desire to serve our
noble people, which has thus clearly manifested its will. So
do I respect this will, now that it is known to me. After
mature deliberation, I resolutely proclaim to the world that I
cannot refuse to heed the voice of a people longing for peace,
nor the lamentations of thousands of families yearning to see
their dear ones enjoying the liberty and the promised
generosity of the great American Nation. By acknowledging and
accepting the sovereignty of the United States throughout the
Philippine Archipelago, as I now do, and without any
reservation whatsoever, I believe that I am serving thee, my
beloved country. May happiness be thine."

PHŒNICIANS, The:
Modified estimates of their influence upon early
European civilization.

See (in this volume)


ARCHÆOLOGICAL RESEARCH: CRETE.

PILLAGER INDIAN OUTBREAK.

See (in this volume)


INDIANS, AMERICAN: A. D. 1898.
PLAGUE, The Bubonic.

For years the plague has "continued to breed in various inner


parts of Asia, and in 1894, coming from the Chinese province
of Yunnan, it invaded Canton, taking there 60,000 victims in a
few weeks. Thence it spread to Hong Kong, reached next year
the island of Haïnan and Macao, invaded Formosa in 1896, and
in the autumn of the same year appeared at Bombay. In the big
city of India it found all necessary conditions for breeding,
unchecked, for several months in succession: famine,
overcrowding, and the absence of all preventive measures; and
from Bombay it was carried by rail and road, to different
parts of India. … Happily enough, the plague is no longer the
mysterious, revengeful being which it used to be for our
ancestors. Its cause and modes of propagation are well known.
It is an infectious disease with a short period of incubation.
From four to six days after infection takes place, a sudden
loss of forces—often a full prostration, accompanied by a high
fever-sets in. A bubo appears, and soon grows to the size of
an egg. Death soon follows. If not—there is a chance of slow
and painful recovery; but that chance is very small, because
even under the best conditions of nursing, the mortality is
seldom less than four out of each five cases of illness. As to
the means of propagation of the plague, they are many. The
poison may infect a wound or a scratch; it may be ingested in
food; it may be simply inhaled. Dust from an infected house
was sufficient to infect healthy rats; and when healthy rats
were shut up in one cage with unhealthy ones, all caught the
disease and died. Already in 1881 Netten Redcliffe and Dr.
Pichon indicated that before the plague attacks men it
destroys mice and rats. This was fully confirmed in 1894 by
the Japanese and French bacteriologists Kitasato and Yersin,
at Hong Kong, and by Dr. Rennie, of the Chinese Customs, at
Canton. Masses of dead rats were seen in the streets of the
infested parts of Hong Kong, and the keeper of the west gates
of Canton collected and buried 24,000 of these animals. Dr.
Rennie also pointed out that among those inhabitants of Canton
who lived in boats on the river there were no cases of plague,
except a few imported from town, so that even rich Cantonese
took to living in boats; and he explained the immunity of the
boat-dwellers by the absence of infection through rats. The
worst is, however, that swine, and even goats and buffaloes,
snakes and jackals, are attacked by the plague. …

"As soon as the plague broke out at Hong Kong, the great
Japanese bacteriologist Kitasato and the French doctor Yersin,
who is well known for his work with Roux on the serum
treatment of diphtheria, were already on the spot. Yersin
obtained from the English authorities permission to erect a
small straw hut in the yard of the chief hospital, and there
he began his researches. Both Kitasato and Yersin had no
difficulty in ascertaining that the plague buboes teemed with
special bacteria, which had the shape of tiny microscopic
sticklets, thickened at their ends. To isolate these bacteria,
to cultivate them in artificial media, and to ascertain the
deadly effects of these cultures upon animals, was soon done
by such masters in bacteriology as Kitasato and Yersin. The
cause of the plague was thus discovered. It was evident that
infected rats and swine—especially swine with the Chinese, who
keep them in their houses—were spreading the disease, in
addition to men themselves. The same bacteria teemed in the
dead animals. As to men, the discharges from their buboes, and
even, in many cases, their expectorations, were full of plague
bacteria. Besides, Yersin soon noticed that in his
'laboratory,' where he was dissecting animals killed by the
plague, the flies died in numbers. He found that they were
infested with the same bacteria, and carried them about:
inoculations of bacteria obtained from the flies at once
provoked the plague in guinea-pigs. Ants, gnats, and other
insects may evidently spread infection in the same way, while
in and round the infested houses the soil is impregnated with
the same bacteria. As soon as the pest microbe became known,
experiments were begun, at the Paris Institut Pasteur, for
finding the means to combat it; and in July 1895 Yersin,
Calmette, and Borel could already announce that some very
promising results had been obtained."

P. Kropotkin,
Recent Science
(Nineteenth Century, July, 1897).

{404}

Of the first appearance of the plague in India, at Bombay, and


the early stages of its spread in that country, the Viceroy,
Lord Elgin, made the following report to the Secretary of
State for India, on the 27th of January, 1897: "The first
official intimation of the outbreak which reached us was in a
telegram from the Government of Bombay, dated the 29th
September 1896. The disease was then reported to be of a mild
type, and at first it showed no tendency to increase. …
Throughout the months of October and November the disease made
little or no progress, and the number of deaths reported a day
averaged nine. Early in December there was a marked increase,
and the number of deaths reported daily from the 2nd to the
23rd (inclusive) was about 32. From the 24th December onwards
there was another marked increase, and the number of deaths
reported from that date to the 14th January (inclusive)
averaged about 51. The next week shows a further increase, the
reported number of deaths averaging 74 a day. The total number
of deaths reported during October was 276; during November,
268; during December, 1,160; and from the 1st to the 25th
January, 1,444. The total number of deaths reported from the
beginning of the outbreak thus amounts to 3,148. We have
reason to fear that all deaths from the plague have not been
reported as such, and that the true mortality from the disease
is higher than is shown by the above figures. … For a
considerable time, except for a few imported cases in some
towns in Gujarat, the outbreak was confined to Bombay itself,
but on the 23rd of December we learnt from the Government of
Bombay that the plague had broken out in Karachi. … The total
number of deaths that have been reported in Karachi, from the
beginning of the outbreak up to the 24th January, is 608. It
will be observed that the disease has been very malignant in
Karachi, and that almost all the cases reported have been
fatal. As soon as the Surgeon General with the Government of
Bombay reported to that Government that he had seen cases of a
mild type of bubonic plague in the city, preventive measures
were adopted and a Committee of medical experts were appointed
to report on the disease and the situation. The Municipal
Corporation have from the outset required the infected
quarters to undergo a thorough and systematic cleaning and
disinfection; and they have also pushed on vigorously other
sanitary measures, such as the improvement of house
connections and the construction of surface drains in quarters
where the drainage was defective. A house-to-house visitation
by medical officers has also been instituted. The Corporation
have sanctioned liberal measures towards these ends, and the
executive officers have displayed great energy in carrying
them out. … We have informed the Government of Bombay that we
consider it necessary that the plan of removing all persons
from infected houses, and thoroughly cleansing and
disinfecting the buildings, should be carried out, and we have
asked His Excellency in Council, if he agrees, to report the
measures that are adopted to bring the plan into general
effect."

To the above suggestion that all persons be removed from


infected houses, the government of Bombay replied, on the 12th
of February: "His Excellency is advised that, to give full
effect to such a proposal, at the lowest computation, 30,000
persons belonging to different races, castes, and creeds would
need to be provided with temporary dwellings. There is no site
within the limits of the Bombay municipality which would
accommodate a tenth of this number. Great difficulty has
attended all attempts at the segregation of healthy inmates of
infected houses hitherto made, and very limited success bas
been achieved. From the beginning of the outbreak of this
disease it has been found that the native inhabitants of the
city are very reluctant to leave their houses or to allow any
member of their family afflicted with the disease to be taken
away. Indeed, their dread of the disease itself appears to be
hardly so powerful as their horror of being removed from their
houses. Ignorance and superstition prevent them from
discerning either that removal to a hospital is good for the
sick or removal [from] infected dwellings good for the
healthy, and they are far more easily moved by fear of the
municipal and police authorities than by any realisation of
the benefits that will accrue from a sensible course of
action. It is estimated that not less than 300,000 persons
have already fled from Bombay, moved so to do, not only by
fear of the plague, but quite as much, if not more, by an
unfounded and unreasonable fear of what might happen to them
at the hands of the police and municipal authorities were they
to remain."

Contending with such obstacles to the use of the most


effective measures for checking the spread of the disease, the
authorities at Bombay and elsewhere, who seem to have worked
with energy, saw little to encourage their efforts for some
time. In a second report to the Secretary of State for India,
made February 10, Lord Elgin was compelled to write: "We much
regret that we are unable to report that the plague shows any
signs of abating. In both Bombay and Karachi there has been an
increase in the daily number of seizures and deaths since the
beginning of the current month." But, a month later, on the
10th of March, the Viceroy reported that "the position of
affairs in Bombay is distinctly better. There has been a
decrease in the reported number of plague seizures and deaths,
and the total daily mortality from all causes shows a marked
diminution. During the week ending the 22nd February, the
average daily number of seizures and deaths was 115 and 117,
respectively; during the following week the daily average fell
to 107 and 99, whilst during the period March 2nd to March 8th
it has been 99 and 84. … Persons are now returning to the
quarters of Bombay, which are comparatively free from plague,
from the more infected outlying suburbs, and the Government of
Bombay have therefore found it necessary to watch persons
entering as well as those leaving Bombay. In the suburbs of
Kurla, Bandora, and Bhiwandi the plague continues to be
severe. Outside Bombay in the Presidency proper the number of
indigenous cases has increased, and the disease shows a
tendency to spread, especially in the Thana and Surat
districts. … Outside Karachi the plague shows no tendency to
spread in Sind, and Sukkur is the only other place from which
indigenous cases have been reported."

Great Britain, Parliamentary Publications


(Papers by Command: C.-8386, 1897; and C.-8511, 1897).

{405}

From that time there appears to have been a nearly steady


subsidence of the disease until the following September, when
it showed renewed virulence at Poona, and began to be newly
spread, invading districts in the Punjab and elsewhere outside
of the Bombay Presidency. By the middle of November Poona was
substantially empty of inhabitants, except those stricken with
the disease and those who bravely cared for the sick and dying.
In December there was a fresh outbreak in Bombay, which soon
became more deadly than that of the previous winter and
spring. By the beginning of February, 1898, and through March,
the deaths from plague alone in Bombay had risen above a
thousand a week. Then another subsidence occurred, followed by
another recrudescence of the disease in August, and another
decline in October. But the variations in other districts were
not uniform with those in Bombay. At the end of 1898, the
total of mortality from plague in all the afflicted districts
of India, reckoning from the beginning, was believed to exceed
100,000, including 70,000 in the Bombay Presidency and Sind
(28,000 in the city of Bombay), and 2,000 in the Punjab. In
Calcutta there had been but 150 deaths. Although the measures
taken for checking the spread of the pestilence were far less
stringent than they would have been among people more capable
of understanding what they meant and what their importance
was, they alarmed the religious jealousies of both the Hindus
and the Mohammedans, and were resisted and resented with
dangerous fury at a number of times. At Poona, in June, 1897,
two British officials were murdered by young Brahmins, who had
been excited to the deed by native journals, the language of
which was so violent that the government found it necessary to
prosecute several for sedition. At Bombay, in March, 1898,
when the plague was at its worst, there were very serious
riots, in which a number of Europeans were killed, and troops
were called to the help of the police before the frenzied mob
could be overcome.

Again, in 1899, there was a revival of the disease in India,


especially at Bombay, during the winter, with a decline in
April and fresh virulence in September. At the end of the year
the estimate of total mortality from plague in India since the
beginning was 250,000.

Of the wider spreading of the pestilence during 1900 the


following summary of information is given in the annual report
of the United States Secretary of the Treasury, in connection
with details of quarantine measures: "The Surgeon-General
reports that plague has been more widely distributed during
the year than was ever known in history, and for the first
time obtained lodgment in the Western Hemisphere, at Santos,
Brazil, in October, 1899. By this it is not meant that the
disease has been actually more prevalent than before, but that
its points of contact have embraced nearly every civilized
country in the world, though its prompt recognition and
application of modern methods have either entirely prevented
its spread or have caused it to disappear after a short period
of infection. The scientific knowledge of the disease renders
it far less to be dreaded than before, but increase in rapid
communication between different parts of the world facilitates
its transportation. In illustration, the fact is cited that 20
vessels have been reported, arriving at as many principal
seaports in different parts of the world, on which plague was
discovered on arrival or had manifested itself during the
voyage. As heretofore, its chief ravages have been in India,
where preventive measures have been hindered by religious
fanaticism. In India during the year there were 66,294 deaths.
Notable outbreaks of the disease occurred in Kobe and in
Formosa, Japan, at Oporto, Santos, Rio de Janeiro, Honolulu,
Sydney, Mauritius, Hongkong, and Glasgow.

"In December, 1899, on account of the apparent spread of this


disease, 12 commissioned officers were detailed by order of
the President for duty in the offices of the United States
consuls at the principal ports in England and on the
Continent. In June, the disease fortunately not having become
as widespread as anticipated, they were recalled, with the
exception of five, who are still retained for the purpose of
furnishing information and for service at any needed point.
Two of those thus retained, when the plague was announced at
Glasgow, Scotland, on August 28, 1900, were immediately sent
to that point and began inspection of vessels for the United
States and also for Canada, by request of that Government,
thus enabling vessels to be entered at ports on this side
without undue restraint. In the laboratory of the Service,
scientific investigations as to the viability of the plague
bacillus and the methods and efficiency of disinfection have
been conducted, and the results, together with excerpts from
all available literature hearing upon the prevention of
plague, have been published in the Public Health Reports,
forming, for this year, a volume containing most complete
information upon this disease. About 700,000 doses of
Haffkine's prophylactic were also prepared in the laboratory
and sent to the United States quarantine officers at home and
abroad, together with large quantities of Yersin's serum,
purchased early in the year from the Pasteur Institute in
Paris. In these two preparations, the one (Haffkine) a
prophylactic and the other (Yersin) both prophylactic and a
cure, the Surgeon-General says that science has effective
methods of combating the spread of this disease."

United States, Secretary of the Treasury,


Annual Report, December 4, 1900.

The "antitoxin, or serum, first prepared by Professor Haffkine


as a plague inoculation, called Haffkine's prophylactic, is
now being used in Bombay and western India with remarkable
results. This prophylactic is prepared by first taking the
plague bacilli, or the young germs, from a person affected
with the plague and cultivating them. These microbes are
killed by artificial means and a high degree of heat. From
these dead germs and their poisonous excrements is produced a
fluid that is believed to have acquired the power, when
injected into the human system, to render the blood immune
from the attack of plague germs and to neutralize their
effect. The injection of such a poison has the effect of an
antitoxin and prevents the system from nourishing plague. A
dead plague germ being inoculated into a person, plague will
not follow. A person after having one attack of the disease is
rarely liable to a second. The person first inoculated is
subject to symptoms of the plague.
{406}
In vaccination for smallpox
a living germ is dealt with, whereas in plague inoculation
dead seed only are injected. … Inoculation is exceedingly
unpopular among the natives. The government has had great
labor in persuading the Hindoo mind of the efficacy of
Haffkine's prophylactic against plague and at the same time of
its utter harmlessness in every other respect. The Hindoo is
suspicious that the dead germs and their toxic excreta may be
of animal rather than vegetable substance, which would make
the injection of the fluid into their body a religious
offense."
United States Consular Reports,
January, 1900, page 101.

"In the present epidemic, plague-spots are scattered over the


whole face of the globe from Sydney to Santos and Hongkong,
and recently from San Francisco suspicious cases have been
reported. The annual pilgrimage of Moslems to worship at the
shrines of Mecca and Medina is now, as in the past, of all
human agencies, the most active in spreading the pest. … Since
Egypt is nearest, plague first appears there in the seaport
towns, particularly Alexandria. Sanitary conditions have
improved vastly, like economics, under British control; and,
last year, what in other times might have been a devastating
epidemic was limited to relatively a few scattered cases.
Recognizing the danger to themselves, the European powers have
been led to take steps, under the Venice Convention, for their
own protection. An international quarantine, under the control
of the Egyptian Sanitary, Maritime, and Quarantine Council, in
which the powers have one vote each and Egypt three, has
established stations at two points on the Red Sea."

American Review of Reviews,


May, 1900.

PLATT AMENDMENT, The.

See (in this volume)


CUBA: A. D. 1901 (FEBRUARY-MARCH).

PLURAL VOTING.

See (in this volume)


BELGIUM: A. D. 1894-1895.

PLYMOUTH COLONY:
Return of the manuscript of Bradford's History to

You might also like