How t update sqlite3 database connected to a treeview in tkinter

I am trying to update a sqlite3 database from a tkinter treeview. It should be relatively simple, but I am stuck

My program consists of two files, one with the functions for the backend, the other with just the tkinter layout and its own functions for the app.

The function in the backend file works fine and I have tested it:

def update_book(book_id, book_title, book_author, book_qty):
    db = sqlite3.connect("bookstore.db")
    cursor = db.cursor()
    cursor.execute("""UPDATE books
    SET title = ?, author = ?, qty = ?
    WHERE id = ?""",
    (book_title, book_author, book_qty, book_id))
    db.commit()
    db.close()

This instead is the function from tkinter layout file, responsible to update the entry. At the moment it updates just the entry on the treeview, but NOT in the database. I tried to print the backed function (update_book()) to see the results, but it return None. I do not understand what am I doing wrong... By the way, 'table' is the Treewview widget.

def update_button():
    selected = table.focus()
    data = table.item(selected, "values")
    table.item(selected, values=(id_text.get(), title_text.get(), author_text.get(), qnty_text.get()))
    print(update_book(id_text.get(), title_text.get(), author_text.get(), qnty_text.get()))

Any help would be appreciated. As I am new to programming, if possible please do not include super difficult stuff to understand.

Thank you



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation