Book Image

Tkinter GUI Programming by Example

Book Image

Tkinter GUI Programming by Example

Overview of this book

Tkinter is a modular, cross-platform application development toolkit for Python. When developing GUI-rich applications, the most important choices are which programming language(s) and which GUI framework to use. Python and Tkinter prove to be a great combination. This book will get you familiar with Tkinter by having you create fun and interactive projects. These projects have varying degrees of complexity. We'll start with a simple project, where you'll learn the fundamentals of GUI programming and the basics of working with a Tkinter application. After getting the basics right, we'll move on to creating a project of slightly increased complexity, such as a highly customizable Python editor. In the next project, we'll crank up the complexity level to create an instant messaging app. Toward the end, we'll discuss various ways of packaging our applications so that they can be shared and installed on other machines without the user having to learn how to install and run Python programs.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Changing the editor's font


As we saw from our blackjack game, fonts in Tkinter are usually handled by a font argument against a widget. The Text widget is no exception, this takes the same argument in the same format—a tuple of (family, size, styles).

To change the font in our text editor, we could decide ourselves what font the editor should be in and hard-code that into the declaration of our TextArea instance. However, we cannot guarantee that the user has that font installed, nor can we assume that they like writing in that font! We also cannot assume what font size the user can read best. The only solution is to allow the user to choose their own font settings and find a way of saving their chosen configuration for the next time they open our application.

Since .yaml files are working out so well, we shall just use these for persistent storage.

Note

Other options for persistent storage include plain text files, pickle, shelve or SQLite (which will be covered in a later chapter of this book...