I have a tkinter interface where I need to display some query results and I need for the user to be able to modify a column and submit the results. Currently to pull the queries I'm doing something like this:
conn = connection_info_goes_here
cur = conn.cursor()
cur.execute(query_goes_here)
And this is my query:
SELECT id, reviewer, task, num_seconds, start_time, end_time
FROM hours
WHERE DATE(start_time) = '2014-12-18'
AND reviewer = 'john'
The field that the user needs to modify is num_seconds
(just numbers). My question is, how do I make the query results show in the grid and how do I make one of the fields modifiable with a button to submit the changes?
Additional info: I already did this in a very messy way using exec()
and programmatically creating variables for each field. It became very long and confusing and I really think there has to be a better and easier way to do this.
Any help is appreciated. Thanks!!
Quick Update: since this was put on hold, i'll add an image of something similar to what I'm looking for:
The values in the entry label must replace the values in the column to the right when I upload them back to the DB.
When I say I did this in a messy way, is because I did (the only way I could think of):
def cor_window():
corrections = Tk()
corrections.title("Corrections")
corrections_frame = ttk.Frame(corrections)
cor_values = []
count=0
cor_count=0
for x in results:
count2=0
for y in results[count]:
if count2 == 3:
exec('int' + str(cor_count) + '=tkinter.StringVar')
exec('int' + str(cor_count) + '_entry = ttk.Entry(corrections, width=20, textvariable=int' + str(cor_count) + ')')
exec('int' + str(cor_count) + '_entry.grid(column=count2, row=count+2)')
cor_count = cor_count+1
cor_values.append('int' + str(cor_count) + '_entry')
ttk.Label(corrections, width=20, anchor=CENTER, relief=SUNKEN, borderwidth=1, text= results[count][count2]).grid(column=count2+1, row=count+2)
elif count2 > 3:
ttk.Label(corrections, width=20, anchor=CENTER, relief=SUNKEN, borderwidth=1, text= results[count][count2]).grid(column=count2+1, row=count+2)
else:
ttk.Label(corrections, width=20, anchor=CENTER, relief=SUNKEN, borderwidth=1, text= results[count][count2]).grid(column=count2, row=count+2)
count2=count2+1
count=count+1
ttk.Button(corrections, text="Done!", command=upload_cor).grid(column=0, row=1)
Where results
is the list that contains the query results and upload_cor
is the function the will upload the changes to the DB. Since I used exec
, even if the user modifies the entry box, I can't use .get()
to get what the user typed. When I try use .get()
, I only get None
even if something was typed in the entry box.
I just need a different method to do this, again, any ideas are welcome.