The View class

Let's start coding our game by first creating a basic View class. This class will be responsible for creating the GUI, checking for game over logic, and most importantly acting as the consumer, taking items from the queue and processing them to update the view (see 9.04_game_of_snake.py):

class View(Tk):  def __init__(self, queue):    Tk.__init__(self)    self.queue = queue    self.create_gui()  def create_gui(self):    self.canvas = Canvas(self, width=495, height=305, bg='#FF75A0')    self.canvas.pack()    self.snake = self.canvas.create_line((0, 0), (0,0),fill='#FFCC4C',       width=10)    self.food = self.canvas.create_rectangle(0, 0, 0, 0,        fill='#FFCC4C', outline='#FFCC4C')    self.points_earned = self.canvas.create_text(455, 15, fill='white',  text='Score:0') ...

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.