Book Image

Tkinter GUI Programming by Example

Book Image

Tkinter GUI Programming by Example

Overview of this book

Tkinter is a modular, cross-platform application development toolkit for Python. When developing GUI-rich applications, the most important choices are which programming language(s) and which GUI framework to use. Python and Tkinter prove to be a great combination. This book will get you familiar with Tkinter by having you create fun and interactive projects. These projects have varying degrees of complexity. We'll start with a simple project, where you'll learn the fundamentals of GUI programming and the basics of working with a Tkinter application. After getting the basics right, we'll move on to creating a project of slightly increased complexity, such as a highly customizable Python editor. In the next project, we'll crank up the complexity level to create an instant messaging app. Toward the end, we'll discuss various ways of packaging our applications so that they can be shared and installed on other machines without the user having to learn how to install and run Python programs.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

The blackjack packages


Begin the rejuvenation of the blackjack game by creating a new folder to hold our new game. For simplicity, I will call this folder blackjack.

Within this folder, create two others: casino and casino_sounds.

The casino folder will become a package holding various aspects of a typical casino. This includes our old Hand, Deck, and Card classes.

The casino package

Within your casino folder, create three files to house these. Name them hand.py, deck.py, and card.py.

In each one, paste in the code from the relevant class.

If you are using an IDE with syntax checking, you may notice a few errors. These are due to the now-missing imports.

In deck.py, ensure you have the following imports:

import random

from .card import Card

The random module is needed to shuffle our deck.

The Deck class also relies on having instances of our Card class, so we need to ensure we have access to it. We achieve this by using a relative import.

The relative import is indicated by a single or double dot...