I am using Python with guizero to build a grid of buttons, like so:
from guizero import App, PushButton, Waffle, Text
def button_click(x, y):
print(f"Button {x+1}-{y+1} wurde geklickt!“)
app = App("Button-Grid", width=600, height=800)
button_grid = Waffle(app, width=8, height=8, dim=50, pad=5, dotty=True, command=button_click)
name = Text(app, text=„“)
app.display()
On the same computer I have installed an sqlite3 database with only one table and a few rows.
Of course, the way to connect to the database is like that:
import sqlite3
conn = sqlite3.connect(‚my_database.db‘)
cursor = conn.cursor()
That is already working.
Now, I would like to write a function that accomplishes the following:
whenever a button is pushed, a corresponding value in the table of my database is updated.
The workflow in combination with the sqlite3 command would look like that:
push a button -> update „my_table“ set „a_column“ = „some_value“;
Since I did not find anything in the documentation or in any forum I searched. Maybe someone could point me in the right direction how to proceed? I just do not know what would do the trick.
The exact question would be: how can I make sure that every button in the grid only corresponds to a single field in the database table I created?
Any hints are very much appreciated. And of course I am willing to give more information if needed ; )
I really do not have a clue how to accomplish this task. So, unfortunately I cannot share anything I have already tried.
I guess the solution will be some kind of function after the database connection is established.
Maybe like that:
def update_db(x, y):
cursor.execute(“update <my_table> set {x+1}-{y+1} = <some_value>;”)
This function will be executed, whenever a button is pushed.
But how I single out a button an make it correspond to a column/field in a database table I have no idea.
Diego_allinone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.