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

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 ...

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