Sqlite3 query to select specific month

Viewed 19

What I want to achieve with this code is that when I select a month from the Combobox, items from the month selected should be displayed on the treeview.

The code does not return an error but the query does not run

Code

def my_func(*args):
    global trv
    con =sqlite3.connect(r'E\res')
    c=con.cursor()
    month=data.get() # Collecting the selected month name
    query="SELECT id,items,quantity, strftime('%y-%m-%d', dt) as dt FROM my_table WHERE \
        strftime('%m',dt ) ='"+month+"'"
    c.execute(query)

data=tk.StringVar()
months=['Jan','Feb','Mar','Apr','May','Jun','Jul',
    'Aug','Sep','Oct','Nov','Dec']
Combo = ttk.Combobox(my_w, values=months,width=7, textvariable=sel)
Combo.grid(row=0,column=0,padx=5,pady=20)


trv = ttk.Treeview(root, selectmode ='browse')
trv.grid(row=2,column=0,columnspan=3,padx=5,pady=20)

data.trace('w',my_func)


root.mainloop()

I didn't post here the treeview. But what I want to achieve is, I want to select a particular month from the combobox and all items in that month should be displayed in my treeview.

0 Answers
Related