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
Tkinter GUI Application Development Blueprints, Second Edition

You're reading from   Tkinter GUI Application Development Blueprints, Second Edition Build nine projects by working with widgets, geometry management, event handling, and more

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788837460
Length 422 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bhaskar Chaudhary Bhaskar Chaudhary
Author Profile Icon Bhaskar Chaudhary
Bhaskar Chaudhary
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Meet Tkinter FREE CHAPTER 2. Making a Text Editor 3. Programmable Drum Machine 4. Game of Chess 5. Building an Audio Player 6. Paint Application 7. Piano Tutor 8. Fun with Canvas 9. Multiple Fun Projects 10. Miscellaneous Tips 11. Other Books You May Enjoy

Getting started

We will write all our projects using Python Version 3.6.3, which is the latest stable release of Python at the time of writing.

The Python download package and instructions for downloading for different platforms are available at https://www.python.org/downloads/release/python-363/.

The installer binaries for macOS X and the Windows platform are available at the aforementioned link.

If you are following along on Unix, Linux, or BSD, the following procedure will install Python from the source.

First, install tk8.6-dev and python3-tk packages on your computer using your applicable package manager. For instance, on Debian-based systems such as Ubuntu and Mint, run the following two commands from the Terminal:

sudo apt install tk8.6-dev
sudo apt install python3-tk

Download Python 3.6.3 from the preceding link and extract it to any location of your choice. Open a Terminal in the location where you extracted Python and type in the following commands:

./configure
make
make test
sudo make altinstall

This should install Python 3.6.3 on your computer. Now open a command line and enter the following command:

$ python3.6

This will open the Python 3.6 interactive shell. Type in the following command:

>>> import tkinter

This command should execute without any errors. If there are no error messages, the Tkinter module is installed on your Python distribution.

When working with examples from this book, we do not support any Python Version except for Python 3.6.3, which comes bundled with Tkinter Tcl/Tk Version 8.6. However, most of the examples should work out-of-the-box on other minor Python 3 Versions.

To check whether you have the correct Tkinter Version on your Python installation, type the following commands in your IDLE or interactive shell:

>>> import tkinter
>>> tkinter._test()

This should confirm the Tcl/Tk Version as 8.6. We are now ready to build our GUI programs!

The next steps are optional and you may skip them at your discretion. While the preceding steps are sufficient for us to develop our programs, I highly recommend that you use a virtual environment for developing your programs.

Virtual environments provide a secluded environment with no conflicts with system programs, and they can be easily reproduced on any other system.

So now let's set up a virtual environment. First, create a folder where you will keep all projects from this book. Let's call it myTkinterProjects or whatever suits you.

Next, find the location of the Python 3.6 installation on your computer. On my computer, I can find the location of the Python installation by running the following command:

$ which python3.6

Take a note of the location. For me it is /usr/local/bin/python3.6. Now open a Terminal in your myTkinterProjects folder and run the following command:

$ virtualenv -p /location/of /python3.6   myvenv/

This will create a new virtual environment in a folder named myvenv inside your project folder.

Lastly, we need to activate this virtual environment. This is done by running the following command:

$ source myenv/bin/activate

Now if you type the command python, it should pick up Python 3.6.3 from within your virtual environment.

From now onward, every time we have to run a Python script or install a new module, we will first activate the virtual environment using the preceding command and run or install the module within this new virtual environment.

You have been reading a chapter from
Tkinter GUI Application Development Blueprints, Second Edition - Second Edition
Published in: Mar 2018
Publisher: Packt
ISBN-13: 9781788837460
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