Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Tkinter GUI Application Development Cookbook
Tkinter GUI Application Development Cookbook

Tkinter GUI Application Development Cookbook: A practical solution to your GUI development problems with Python and Tkinter

Arrow left icon
Profile Icon Alejandro Rodas de Paz
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (7 Ratings)
Paperback Mar 2018 242 pages 1st Edition
eBook
Mex$648.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial
Arrow left icon
Profile Icon Alejandro Rodas de Paz
Arrow right icon
Free Trial
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (7 Ratings)
Paperback Mar 2018 242 pages 1st Edition
eBook
Mex$648.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial
eBook
Mex$648.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Tkinter GUI Application Development Cookbook

Window Layout

In this chapter, we will cover the following recipes:

  • Grouping widgets with frames
  • Using the Pack geometry manager
  • Using the Grid geometry manager
  • Using the Place geometry manager
  • Grouping inputs with the FrameLabel widget
  • Dynamically laying out widgets
  • Creating horizontal and vertical scrollbars

Introduction

Widgets determine the actions that users can perform with our GUI application; however, we should pay attention to their placement and the relationships we establish with that arrangement. Effective layouts help users to identify the meaning and priority of each graphical element so that they can quickly understand how to interact with our program.

Layout also determines the visual appearance that users expect to find consistently across the whole application, such as always placing confirmation buttons at the bottom-right corner of the screen. Although this information might be obvious to us as developers, end users may feel overwhelmed if we do not guide them through the application by following a natural order.

This chapter will dive into the different mechanisms that Tkinter offers to lay out and group widgets and control other attributes, such as their size or...

Grouping widgets with frames

A frame represents a rectangular region of a window, typically used in complex layouts to contain other widgets. Since they have their own padding, border, and background, you can remark that the group of widgets is related logically.

Another common pattern for frames is to encapsulate part of the application's functionality so that you can create an abstraction that hides the implementation details of child widgets.

We will see an example that covers both scenarios by creating a component that inherits from the Frame class and exposes certain information on the containing widgets.

Getting ready

We will build an application that contains two lists, where the first one has a list of items and...

Using the Pack geometry manager

In previous recipes, we have seen that creating a widget does not automatically display it on the screen. We have called the pack() method on each widget to do so, which means that we used the Pack geometry manager.

This is one of the three available geometry managers in Tkinter, and it is well suited for simple layouts, such as when you want to place all the widgets on top of each other or side by side.

Getting ready

Let's suppose that we want to achieve the following layout in our application:

It consists of three rows, where the last one has three widgets placed side by side. In this scenario, the Pack geometry manager can easily add the widgets as expected, without the need for additional...

Using the Grid geometry manager

The Grid geometry manager is considered the more versatile of the three geometry managers. It directly reassembles the grid concept that is commonly used in user interface design—a two-dimensional table divided into rows and columns, where each cell represents the space available for a widget.

Getting ready

We will demonstrate how to use the Grid geometry manager to achieve the following layout:

This can be represented as a 3 x 3 table, where the widgets in the second and third columns span two rows and the widget at the bottom row spans three columns.

How to do it...

...

Using the Place geometry manager

The Place geometry manager allows you to set the position and size of a widget in absolute terms, or in relative terms to another one.

Of the three geometry managers, it is the least commonly used one. On the other hand, it can fit some complex scenarios where you want to freely position a widget or overlap a previously placed one.

Getting ready

To demonstrate how to work with the Place geometry manager, we will replicate the following layout by mixing absolute and relative positions and sizes:

How to do it...

The labels that we will display...

Grouping inputs with the LabelFrame widget

The LabelFrame class can be used to group multiple input widgets, indicating the logical entity with a label they represent. It is typically used in forms and is very similar to the Frame widget.

Getting ready

We will build a form with a couple of LabelFrame instances, each one with their corresponding child input widgets:

How to do it...

Since the purpose of this example is to show the final layout, we will add some widgets, without keeping their references as attributes:

import tkinter as tk

class App(tk.Tk):
def __init__...

Dynamically laying out widgets

The Grid geometry manager is easy to use both in simple and advanced layouts, and it is also a powerful mechanism to combine with a list of widgets.

We will take a look at how we can reduce the number of lines and call the geometry manager methods with just a few lines, thanks to list comprehensions and the zip and enumerate built-in functions.

Getting ready

The application we will build contains four Entry widgets, each one with its corresponding label that indicates the meaning of the input. We will also add a button to print all the entries' values:

Instead of creating and assigning each widget to a separate attribute, we will work with lists of widgets. Since we will track the index...

Creating horizontal and vertical scrollbars

In Tkinter, geometry managers take all the necessary space to fit all the widgets in their parent container. However, if the container has a fixed size or exceeds the screen's size, there will be a region that will not be visible to users.

Scroll bar widgets are not automatically added in Tkinter, so you must create and lay them out as any other type of widget. Another consideration is that only a few widget classes have the configuration options that make it possible to connect them to a scrollbar.

To work around this, you will learn to take advantage of the flexibility of the Canvas widget to make any container scrollable.

Getting ready

To demonstrate the combination of the...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • • Integrate efficient Python GUI programming techniques with Tkinter
  • • Efficiently implement advanced MVC architectures in your Python GUI apps
  • • Solve all your problems related to Tkinter and Python GUI development

Description

As one of the more versatile programming languages, Python is well-known for its batteries-included philosophy, which includes a rich set of modules in its standard library; Tkinter is the library included for building desktop applications. Due to this, Tkinter is a common choice for rapid GUI development, and more complex applications can benefit from the full capabilities of this library. This book covers all of your Tkinter and Python GUI development problems and solutions. Tkinter GUI Application Development Cookbook starts with an overview of Tkinter classes and at the same time provides recipes for basic topics, such as layout patterns and event handling. Next, we cover how to develop common GUI patterns, such as entering and saving data, navigating through menus and dialogs, and performing long-running actions in the background.You can then make your apps leverage network resources effectively and perform graphical operations on a canvas and related tasks such as detecting collisions between items. Finally, this book covers using themed widgets, an extension of Tk widgets that have a more native look and feel. Finally, this book covers using the canvas and themed widgets. By the end of the book, you will have an in-depth knowledge of Tkinter classes, and will know how to use them to build efficient and rich GUI applications.

Who is this book for?

This book is for Python developers who are familiar with the basics of the language syntax, data structures, and OOP. You do not need previous experience with Tkinter or other GUI development libraries.

What you will learn

  • • Add widgets and handle user events
  • • Lay out widgets within windows using frames and the different geometry managers
  • • Configure widgets so that they have a customized appearance and behavior
  • • Improve the navigation of your apps with menus and dialogs
  • • Apply object-oriented programming techniques in Tkinter applications
  • • Use threads to achieve responsiveness and update the GUI
  • • Explore the capabilities of the canvas widget and the types of items that can be added to it
  • • Extend Tkinter applications with the TTK (themed Tkinter) module

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 30, 2018
Length: 242 pages
Edition : 1st
Language : English
ISBN-13 : 9781788622301
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Mar 30, 2018
Length: 242 pages
Edition : 1st
Language : English
ISBN-13 : 9781788622301
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,160.97
Tkinter GUI Application Development Blueprints, Second Edition
Mex$1128.99
Tkinter GUI Application Development Cookbook
Mex$902.99
Tkinter GUI Programming by Example
Mex$1128.99
Total Mex$ 3,160.97 Stars icon

Table of Contents

9 Chapters
Getting Started with Tkinter Chevron down icon Chevron up icon
Window Layout Chevron down icon Chevron up icon
Customizing Widgets Chevron down icon Chevron up icon
Dialogs and Menus Chevron down icon Chevron up icon
Object-Oriented Programming and MVC Chevron down icon Chevron up icon
Asynchronous Programming Chevron down icon Chevron up icon
Canvas and Graphics Chevron down icon Chevron up icon
Themed Widgets Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(7 Ratings)
5 star 57.1%
4 star 28.6%
3 star 14.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




René BELLE Oct 15, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Comme savent si bien le faire les Américains, cet ouvrage pratique et d'un niveau gradué présentent moultes séquences de code afin d'illustrer la programmation d'applications de classes en Python grâce à la bibliothèque Tkinter. La méthode de formation basée sur la lecture et l'expérimentation du code suivie d'un bref exposé du fonctionnement du programme est simple, claire et efficace dans le but de former l'étudiant que je suis. En tête d'ouvrage, l'index des séquences de code en fait un outil efficace pour piocher par ci, par là, des idées permettant de développer une application et d'assembler les modules comme les Legos qui étaient mon jeu favori entre 8 et 12 ans. C'est bien un Cookbook (livre de recettes) que nous avons là entre les mains. Bien qu'en anglais, il se lit très facilement et la mise en pratique du code permet de mémoriser les tournures syntaxiques, la grammaire et l'orthographe des commandes.C'est un ouvrage de base que je recommande à tous les amateurs de Python et d'applications graphiques faciles à développer rapidement. Pour l'instant au bout de 1500 pages de lectures sur le sujet (sur un total prévisionnel de 500à pages au courant de l'hiver), c'est mon préféré car le plus en rapport avec une pratique immédiate chère à l'autodidacte que je suis encore à 67 ans.
Amazon Verified review Amazon
HARSH GURJAR May 06, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Best book for beginners for Python tkinter. Just go for it.
Amazon Verified review Amazon
Amit Nath Gupta Jan 22, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent to guide you through tkinterThanks for writing such a book.Author is great.Buy the kindle edition ,it is better
Amazon Verified review Amazon
KML Dec 24, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Bought this direct from Packt as they are offering a $5 per book holiday special. In the universe of Tkinter books, there are few good works. Tkinter in Action from Manning is one such but it's really outdated.This book does not attempt to cover everything but it does provide practical essentials that work, including threading which is critical in most non-trivial apps. Code quality is also excellent. Has the best explanation of the pack geometry manager. Hope the author can write a cookbook or one on advanced features.
Amazon Verified review Amazon
Clive Aug 12, 2020
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
I suspect this book will be useful, but contrary to what is described, I am not sold on it being easy for those who haven't used Tkinter to follow.Within the first chapter there are several references to object types which aren't explained. Sure you may be able to learn these code section by rote, but that doesn't help you to understand the software. For this reason I ended up purchasing another book to complement this one.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.