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

Adding server endpoints

We will need two endpoints to make full use of our avatars – one to upload a new one, and one to fetch an avatar for a particular user.

Open up server.py and add the following functions:

@app.route("/update_avatar/<username>", methods=["POST"])def update_avatar(username):    img_b64 = request.form.get("img_b64")    database.update_avatar(username, img_b64)    return jsonify({        "success": True    })

This first endpoint will store the base64 encoded image data in the database against the username provided in the URL:

@app.route("/get_user_avatar/<username>")def get_avatar(username):    avatar_b64 = database.get_user_avatar(username)['avatar']    return jsonify({        "avatar": avatar_b64    })

The second endpoint will get the user's base64 encoded ...

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