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 with Tkinter

You're reading from   Python GUI Programming with Tkinter Develop responsive and powerful GUI applications with Tkinter

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788835886
Length 452 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
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 (17) Chapters Close

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. Maintaining Cross-Platform Compatibility 10. Creating Automated Tests with unittest 11. Improving Data Storage with SQL 12. Connecting to the Cloud 13. Asynchronous Programming with Thread and Queue 14. Visualizing Data Using the Canvas Widget 15. Packaging with setuptools and cx_Freeze 16. 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 with Tkinter
Published in: May 2018
Publisher: Packt
ISBN-13: 9781788835886
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