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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python GUI Programming Cookbook

You're reading from   Python GUI Programming Cookbook Develop functional and responsive user interfaces with tkinter and PyQt5

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher
ISBN-13 9781838827540
Length 486 pages
Edition 3rd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Burkhard Meier Burkhard Meier
Author Profile Icon Burkhard Meier
Burkhard Meier
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Creating the GUI Form and Adding Widgets FREE CHAPTER 2. Layout Management 3. Look and Feel Customization 4. Data and Classes 5. Matplotlib Charts 6. Threads and Networking 7. Storing Data in Our MySQL Database via Our GUI 8. Internationalization and Testing 9. Extending Our GUI with the wxPython Library 10. Building GUIs with PyQt5 11. Best Practices 12. Other Books You May Enjoy

Creating the GUI Form and Adding Widgets

In this chapter, we will develop our first GUI in Python. We will start with the minimum code required to build a running GUI application. Each recipe then adds different widgets to the GUI form.

We will start by using the tkinter GUI toolkit.

tkinter ships with Python. There is no need to install it once you have installed Python version 3.7 or later. The tkinter GUI toolkit enables us to write GUIs with Python.

The old world of the DOS Command Prompt has long been outdated. Some developers still like it for development work. The end user of your program expects a more modern, good-looking GUI.

In this book, you will learn how to develop GUIs using the Python programming language.

By starting with the minimum amount of code, we can see the pattern every GUI written with tkinter and Python follows. First come the import statements, followed by the creation of a tkinter class. We then can call methods and change attributes. At the end, we always call the Windows event loop. Now we can run the code.
We progress from the most simple code, adding more and more functionality with each following recipe, introducing different widget controls and how to change and retrieve attributes.

In the first two recipes, we will show the entire code, consisting of only a few lines of code. In the following recipes, we will only show the code to be added to the previous recipes because, otherwise, the book would get too long, and seeing the same code over and over again is rather boring.

If you don't have the time to type the code yourself, you can download all of the code for the entire book from https://github.com/PacktPublishing/Python-GUI-Programming-Cookbook-Third-Edition.

At the beginning of each chapter, I will show the Python modules that belong to each chapter. I will then reference the different modules that belong to the code shown, studied, and run.

By the end of this chapter, we will have created a working GUI application that consists of labels, buttons, textboxes, comboboxes, check buttons in various states, and radio buttons that change the background color of the GUI.

Here is an overview of the Python modules (ending in a .py extension) for this chapter:

In this chapter, we start creating amazing GUIs using Python 3.7 or later. We will cover the following topics:

  • Creating our first Python GUI
  • Preventing the GUI from being resized
  • Adding a label to the GUI form
  • Creating buttons and changing their text attributes
  • Creating textbox widgets
  • Setting the focus to a widget and disabling widgets
  • Creating combobox widgets
  • Creating a check button with different initial states
  • Using radio button widgets
  • Using scrolled text widgets
  • Adding several widgets in a loop
You have been reading a chapter from
Python GUI Programming Cookbook - Third Edition
Published in: Oct 2019
Publisher:
ISBN-13: 9781838827540
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image