I am using SQLite and tkinter in Python 3.9 and got the following problem:
I got 1 SQLite DB with 2 tables.
I am using the column of one of the tables for a tkinter option menu.
Now I want to trace the variable selected and display a corresponding value from the other table on a tk.label
. OptionMenu and label are in the same window.
This is what I tried but returns:
TypeError: 'NoneType' object is not callable
def callBackFct(var):
cur.execute("""SELECT nameFromColumn FROM sqlDbTable WHERE condition = ?""", (var,))
f = cur.fetchall()
tkLabel1.config(text = f[0][0])
optionMenuVar1.trace("w", callBackFct(optionMenuVar1.get()))
If I let the function get the variable like this...
def callBackFct(*args):
var = optionMenuVar1.get() # getting variable inside function
cur.execute("""SELECT nameFromColumn FROM sqlDbTable WHERE condition = ?""", (var,))
f = cur.fetchall()
tkLabel1.config(text = f[0][0])
optionMenuVar1.trace("w", callBackFct))
it works, but I have 50 labels and dont want to copy + paste 50 functions. There hast to be a more elegant solution right, where I can give an argument to the callback function?! Please help. It seems like I have missunderstood something basic...