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

Using JSON

Let's modify our simple example to return JSON instead of a web page:

from flask import Flask, jsonify...@app.route("/")def index():    data = {        "cats": 5,        "people": 8,        "dogs": 4    }    return jsonify(data) ...

Flask comes with a module called jsonify, which translates a dictionary into JSON and returns it as the response. This makes handling JSON data very easy.

In this example, we create a dictionary with some example values. In a proper application, this could instead be data which has been pulled from a database and manipulated in some way.

This data is then passed to the jsonify function and given to the requesting application in JSON format.

Make sure your web server is running (run python3 server.py if it isn't), then open up a ...

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