O'Reilly logo

Tkinter GUI Programming by Example by David Love

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 ListeningThread class

Our ListeningThread class will need to inherit from threading.Thread and contain a run method, which can happen in the background.

Since we want to be always checking for new messages until the user closes their ChatWindow, we shall put our request inside a loop which the ChatWindow will be able to end when closed.

Let's begin our ListeningThread class, as follows:

import arrowimport threadingimport timefrom requester import Requester

Our class will be making use of the following modules:

  • arrow: This is used to create the timestamps
  • threading: This is used to run in the background
  • time: This is used to sleep for two seconds between requests
  • requester: This is used to contact our web service

With the imports taken ...

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