Reader small image

You're reading from  Tkinter GUI Application Development Blueprints

Product typeBook
Published inNov 2015
Reading LevelExpert
PublisherPackt
ISBN-139781785889738
Edition1st Edition
Languages
Right arrow
Author (1)
Bhaskar Chaudhary
Bhaskar Chaudhary
author image
Bhaskar Chaudhary

Bhaskar Chaudhary is a professional programmer and information architect. He has a decade of experience in consulting, contracting, and educating in the field of software development. He has worked with a large set of programming languages on various platforms over the years. He is an electronics hobbyist and a musician in his free time.
Read more about Bhaskar Chaudhary

Right arrow

Building a Snake game


Let's now build a simple Snake game. As usual, we will be making use of the Canvas widget to provide the platform for our Snake program.

We will use canvas.create_line to draw our snake, and canvas.create_rectangle to draw the snake food.

The primary objective for this project is to learn how to use Queue as a synchronization technique in a multithreaded application.

Writing a multithreaded application poses the challenge of synchronization between different threads. When multiple threads try to access shared data simultaneously, the data is likely to get corrupted or modified in ways that were not intended in the program. This is called a race condition.

7.02_race_condition.py demonstrates a race condition. The program is as follows:

import threading

class RaceConditionDemo:

    def __init__(self):
        self.shared_var = 0 
        self.total_count = 100000
        self.demo_of_race_condition()

    def increment(self):
        for i in range(self.total_count):
  ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Tkinter GUI Application Development Blueprints
Published in: Nov 2015Publisher: PacktISBN-13: 9781785889738

Author (1)

author image
Bhaskar Chaudhary

Bhaskar Chaudhary is a professional programmer and information architect. He has a decade of experience in consulting, contracting, and educating in the field of software development. He has worked with a large set of programming languages on various platforms over the years. He is an electronics hobbyist and a musician in his free time.
Read more about Bhaskar Chaudhary