O'Reilly logo

Tkinter GUI Application Development Blueprints - Second Edition by Bhaskar Chaudhary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Snake class

Let's now create the Snake class. We have already passed a task to generate our food to the central queue. However, no additional thread was involved in the task. We could also generate our Snake class without using threads. However, because we are talking about ways to implement multithreaded applications, let's implement our Snake class to work from a separate thread (see 9.04_game_of_snake.py):

class Snake(threading.Thread):    is_game_over = False  def __init__(self, queue):    threading.Thread.__init__(self)    self.queue = queue    self.daemon = True    self.points_earned = 0    self.snake_points = [(495, 55), (485, 55), (475, 55), (465, 55),       (455, 55)]    self.food = Food(queue)    self.direction = 'Left'    self.start()  def run(self): while ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required