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

Queue handler

Now that the queue is getting populated with various actionables, let's create the queue_handler method to process the items in the queue and update the View accordingly.

We define the queue_handler() method in our View class as follows:

def queue_handler(self): try:   while True:     task = self.queue.get_nowait()     if 'game_over' in task:       self.game_over()     elif 'move' in task:       points = [x for point in task['move'] for x in point]       self.canvas.coords(self.snake, *points)     elif 'food' in task:       self.canvas.coords(self.food, *task['food'])     elif 'points_earned' in task:       self.canvas.itemconfigure(self.points_earned, text='Score:                                 {}'.format (task['points_earned']))      self.queue.task_done() except queue.Empty: self.after(100, self.queue_handler) ...

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