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

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