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

Selecting data from a SQLite database

A select statement needs to know the table being read and the fields which the user wants returned. The basic syntax is as follows:

SELECT field1, field2 FROM table;

So, to read the users from our users table, we can do the following:

SELECT username, real_name from users;

Again, as we will be doing this repeatedly, writing a function that will do it for us is a good idea.

Add the following to database.py:

def get_all_users():    sql = "SELECT username, real_name FROM users"    params = []    return perform_select(sql, params)

Here, we provide the basic select statement as the sql variable and an empty list as the params variable, since we do not need to include any user-supplied data.

Once again, everything which ...

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