Skip to Content
Tkinter GUI Programming by Example
book

Tkinter GUI Programming by Example

by David Love
April 2018
Beginner content levelBeginner
340 pages
7h 54m
English
Packt Publishing
Content preview from Tkinter GUI Programming by Example

Creating the Requester class

Make yourself a new file in the same folder as your friendslist.py file named requester.py:

import jsonimport requestsclass Requester:    def __init__(self):        self.url = "http://127.0.0.1:5000"

As the name implies, the Requester class will be making use of the requests module to communicate with our web service. We will also need to use the json module to read any data which is returned.

In our __init__, we just need to keep a reference to the URL at which our web service operates. Keeping it here means that, if we change it for any reason, we only have one place in this class to update.

Since our web service uses both GET and POST endpoints, we can generalize our requesting by extracting it to a method:

def request(self, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Tkinter GUI Application Development Blueprints, Second Edition - Second Edition

Bhaskar Chaudhary

Publisher Resources

ISBN: 9781788627481Supplemental Content