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 now! 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
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python GUI Programming - A Complete Reference Guide

You're reading from   Python GUI Programming - A Complete Reference Guide Develop responsive and powerful GUI applications with PyQt and Tkinter

Arrow left icon
Product type Course
Published in Jun 2019
Publisher Packt
ISBN-13 9781838988470
Length 746 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
B. M. Harwani B. M. Harwani
Author Profile Icon B. M. Harwani
B. M. Harwani
Alan D. Moore Alan D. Moore
Author Profile Icon Alan D. Moore
Alan D. Moore
Arrow right icon
View More author details
Toc

Table of Contents (28) Chapters Close

Title Page
Copyright About Packt Contributors Preface 1. Introduction to Tkinter FREE CHAPTER 2. Designing GUI Applications with Tkinter 3. Creating Basic Forms with Tkinter and ttk Widgets 4. Reducing User Error with Validation and Automation 5. Planning for the Expansion of Our Application 6. Creating Menus with Menu and Tkinter Dialogs 7. Navigating Records with Treeview 8. Improving the Look with Styles and Themes 9. Creating Automated Tests with unittest 10. Improving Data Storage with SQL 11. Connecting to the Cloud 12. Visualizing Data Using the Canvas Widget 13. Creating a User Interface with Qt Components 14. Event Handling - Signals and Slots 15. Understanding OOP Concepts 16. Understanding Dialogs 17. Understanding Layouts 18. Networking and Managing Large Documents 19. Database Handling 20. Using Graphics 21. Implementing Animation 22. Using Google Maps 1. Other Books You May Enjoy

Introducing IDLE

IDLE is an integrated development environment that is bundled with the Windows and macOS Python distributions (it's readily available in most Linux distributions as well, usually as IDLE or IDLE3). IDLE is written in Python using Tkinter, and it provides us with not only an editing environment for Python, but also a great example of Tkinter in action. So, while IDLE's rudimentary feature set may not be considered professional grade by many Python coders, and while you may already have a preferred environment for writing Python code, I encourage you to spend some time using IDLE as you go through this book.

Let's get familiar with IDLE's two primary modes: shell mode and editor mode.

Using the shell mode of IDLE

When you launch IDLE, you begin in shell mode, which is simply a Python Read-Evaluate-Print-Loop (REPL) similar to what you get when you type python in a terminal window.

Take a look at the shell mode in the following screenshot:

IDLE's shell has some nice features that you don't get from the command-line REPL, like syntax highlighting and tab-completion. The REPL is essential to the Python development process, as it gives you the ability to test code in real time and inspect classes and APIs without having to write complete scripts. We'll use the shell mode in later chapters to explore the features and behaviors of modules. If you don't have a shell window open, you can open one by clicking on Start, then selecting Run, and searching for Python shell.

Using the editor mode of IDLE

Editor mode is for creating Python script files, which you can later run. When the book tells you to create a new file, this is the mode you'll use. To open a new file in the editor mode, simply navigate to File | New File in the menu or hit Ctrl + N on the keyboard. 

The following is a window where you can start typing a script:

You can run your script without leaving IDLE by hitting F5 in the editor mode; the output will show up in a shell window.

IDLE as a Tkinter example

Before we start coding with Tkinter, let's take a quick look at what you can do with it by inspecting some of IDLE's UI. Navigate to Options | Configure IDLE from the main menu to open IDLE's configuration settings, where you can change IDLE's fonts, colors and theme, keyboard shortcuts, and default behaviors, as shown in the following screenshot:

Consider some of the following components that make up this user interface:

  • There are drop-down lists and radio buttons that allow you to select between different options
  • There are many push buttons that you can click on to execute actions
  • There is a text window that can display multi-colored text
  • There are labeled frames that contain groups of components

Each of these components is known as a widget; we're going to meet these widgets and more throughout this book and learn how to use them as they've been used here. We'll begin, however, with something much simpler.

You have been reading a chapter from
Python GUI Programming - A Complete Reference Guide
Published in: Jun 2019
Publisher: Packt
ISBN-13: 9781838988470
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