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 ...

Get Tkinter GUI Application Development Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.