Jan-22-2020, 03:02 AM
Hi, hopefully quick and simple; I'm currently trying to assign a preexisting button to an execute function which uploads data filled in via GUI to an already existing database however I'm receiving a syntax error in doing so, here's what I got hopefully not too bad!
Full Code:

Full Code:
from tkinter import * import sqlite3 # Database Creation & Filename conn = sqlite3.connect('Expense_Data.db') # Create Cursor connecting to database c = conn.cursor() # Database Table Creation ''' c.execute("""CREATE TABLE expenses ( name text, monthly_income integer, monthly_budget integer, monthly_cost_in_expenses integer )""") ''' def b3(): c.execute("INSERT INTO Expense_Data.db VALUES :l1, :l2, :l3, :l4)" { 'l1': l1.get(), 'l2': l2.get(), 'l3': l3.get(), 'l4': l4.get() }) # Finalise || Commit Changes conn.commit() # Create Window Object window = Tk() # Define table contents (each row/column) l1 = Label(window, text="Name") l1.grid(row=0, column=0) l2 = Label(window, text="Monthly Income") l2.grid(row=1, column=0) l3 = Label(window, text="Monthly Budget") l3.grid(row=2, column=0) l4 = Label(window, text="Monthly Expenses") l4.grid(row=3, column=0) # Define Entries name_text = StringVar() e1 = Entry(window, textvariable=name_text) e1.grid(row=0, column=1) Monthly_Income_text = StringVar() e2 = Entry(window, textvariable=Monthly_Income_text) e2.grid(row=1, column=1) Monthly_Budget = StringVar() e3 = Entry(window, textvariable=Monthly_Budget) e3.grid(row=2, column=1) Monthly_Expenses = StringVar() e4 = Entry(window, textvariable=Monthly_Expenses) e4.grid(row=3, column=1) # Define ListBox list1 = Listbox(window, height=6, width=35) # check this list1.grid(row=5, column=0, columnspan=2) # Attach scrollbar to the list sb1 = Scrollbar(window) sb1.grid(row=2, column=2, rowspan=6) list1.configure(yscrollcommand=sb1.set) sb1.configure(command=list1.yview) # Define buttons b1 = Button(window, text="View All", width=12) b1.grid(row=2, column=3) b2 = Button(window, text="Search Entry", width=12) b2.grid(row=3, column=3) b3 = Button(window, text="Add Entry", width=12) b3.grid(row=4, column=3) b4 = Button(window, text="Update Selected", width=12, command=submit) b4.grid(row=5, column=3) b5 = Button(window, text="Delete Selected", width=12) b5.grid(row=6, column=3) b6 = Button(window, text="Close", width=12) b6.grid(row=7, column=3) window.mainloop()Traceback error:
Error: File "C:/Users/jumbu/Desktop/python/test.py", line 21
{
^
SyntaxError: invalid syntax
Location of Error:def b3(): c.execute("INSERT INTO Expense_Data.db VALUES :l1, :l2, :l3, :l4)" { 'l1': l1.get(), 'l2': l2.get(), 'l3': l3.get(), 'l4': l4.get() })Feel free to take your time, any assistance will be greatly, greatly appreciated!!
