Book Image

Tkinter GUI Application Development Blueprints

By : Bhaskar Chaudhary
Book Image

Tkinter GUI Application Development Blueprints

By: Bhaskar Chaudhary

Overview of this book

Tkinter is the built-in GUI package that comes with standard Python distributions. It is a cross-platform package, which means you build once and deploy everywhere. It is simple to use and intuitive in nature, making it suitable for programmers and non-programmers alike. This book will help you master the art of GUI programming. It delivers the bigger picture of GUI programming by building real-world, productive, and fun applications such as a text editor, drum machine, game of chess, media player, drawing application, chat application, screen saver, port scanner, and many more. In every project, you will build on the skills acquired in the previous project and gain more expertise. You will learn to write multithreaded programs, network programs, database driven programs and more. You will also get to know the modern best practices involved in writing GUI apps. With its rich source of sample code, you can build upon the knowledge gained with this book and use it in your own projects in the discipline of your choice.
Table of Contents (15 chapters)
Tkinter GUI Application Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Tkinter GUI Application Development Blueprints will walk you through the process of developing real-world graphical applications using Python and Tkinter, the built-in GUI module of Python.

This book attempts to highlight the features and capabilities of Tkinter while demonstrating best practices involved in writing GUI programs, irrespective of the library that you choose to build your application with. Here, you will learn how to use Tkinter to develop exciting, fun, and useful GUI applications with Tkinter and Python.

We hope to take you on a fun journey through more than 10 projects from different problem domains. As we develop new applications in each project, the book also builds up a catalog of some commonly used strategies to develop real-world applications.

What this book covers

Chapter 1, Meet Tkinter, begins from scratch, providing an overview of Tkinter and covering details of how to create root windows, add widgets to a root window, handle layout with geometry managers, and work with events.

Chapter 2, Make a Text Editor, develops a text editor in the procedural style of programming. It gives readers their first taste of several features of Tkinter and what it is like to develop a real application.

Chapter 3, Programmable Drum Machine, uses object-oriented programming to develop a drum machine that is capable of playing user-composed rhythms. The application can also save compositions and later edit or replay them. Here, you will learn the techniques of designing a GUI application using a model-first philosophy and how to write multithreaded GUI applications.

Chapter 4, A Game of Chess, introduces key aspects of structuring a GUI application using the model-view-controller (MVC) architecture. It also teaches the art of taking a real-world object (chess) and modeling it in the notations that your program can manipulate. It also introduces readers to the power of the Tkinter Canvas widget.

Chapter 5, Building an Audio Player, introduces the concepts of working with external libraries while showing you how to work with many different Tkinter widgets. Most importantly, it shows how to make your own Tkinter widgets, thereby extending the capabilities of the Tkinter manifold.

Chapter 6, Paint Application, looks at the Tkinter Canvas widget in detail. As you will see, the Canvas widget is truly a highlight of Tkinter. The chapter also introduces the concept of the GUI framework, thereby creating reusable code for all your future programs.

Chapter 7, Multiple Fun Projects, works through a series of small but functional projects, demonstrating problems from different domains such as animation, network programming, socket programming, database programming, making graphs, and multithreaded programming.

Chapter 8, Miscellaneous Tips, discusses some vital aspects of GUI programming that, though not covered in the previous chapters, form a common theme in many GUI programs.

What you need for this book

The programs discussed in this book have been developed on the Ubuntu platform. However, given the multiplatform abilities of Tkinter, you can easily work along on other platforms such as Windows, Mac OS, and other distributions of Linux.

For this book, you will require Python version 3.4 with Tkinter 8.6 in most parts of the distribution. The links to download and install other project-specific modules and software are mentioned in the respective chapters.

Who this book is for

Software developers, scientists, researchers, engineers, students, and programming hobbyists with a basic familiarity with Python will find this book interesting and informative. A motivated Python newbie with a background in writing programs can fill in the gaps of knowledge with a little outside research.

People familiar with basic programming constructs in other programming languages can also catch up with some brief reading on Python. No GUI programming experience is expected.

Conventions

In this book, you will find a number of text styles 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, dummy URLs, user input, and Twitter handles are shown as follows: "The reset_to_initial_locations() method initializes all the chess piece locations to reflect the starting position of the game."

A block of code is set as follows:

def toggle_play_button_state(self):
    if self.now_playing:
        self.play_button.config(state="disabled")
    else:
        self.play_button.config(state="normal")

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

def on_loop_button_toggled(self):
    self.loop = self.to_loop.get()
    self.keep_playing = self.loop
    if self.now_playing:
        self.now_playing = self.loop
    self.toggle_play_button_state()

Any command-line input on the Python interactive shell is written as follows:

>>> import pyglet
>>> help(pyglet.media)

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "When a user clicks on the Cancel button, we simply want the settings window to close."

Note

Warnings or important notes appear in a box like this.

Tip

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 , 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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

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/9738OS_ColoredImages.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/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

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 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 , and we will do our best to address the problem.