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

Creating a scrollable frame


There will come a time when writing applications with Tkinter when you will want to add a Scrollbar to the application as a whole, rather than an individual widget (such as the Text widget, which we have already covered). This is not a trivial task, since Tkinter will usually expand itself to show all of its containing widgets, or if the geometry is already set, will simply hide them underneath the bottom border of the window.

Let's take a look at what I mean. Open a new Python script and type the following short snippet:

import tkinter as tk

win = tk.Tk()

for _ in range(30):
    tk.Label(win, text="big label").pack(pady=20)

win.mainloop()

If you run this file you should see a very tall window open up. You will see a certain number of Label widgets (depending on your monitor's resolution) but will likely not see all 30.

If you have the ability to move the window above the top of your screen (on my Linux machine I can hold Alt and drag the middle of the window upwards...