Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
€17.99 €26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (7 Ratings)
eBook Mar 2018 242 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Alejandro Rodas de Paz
Arrow right icon
€17.99 €26.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (7 Ratings)
eBook Mar 2018 242 pages 1st Edition
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€17.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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 : 9781788627771
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.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
€189.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 €5 each
Feature tick icon Exclusive print discounts
€264.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 €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 116.97
Tkinter GUI Application Development Blueprints, Second Edition
€41.99
Tkinter GUI Application Development Cookbook
€32.99
Tkinter GUI Programming by Example
€41.99
Total 116.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

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.