Home > front end >  Tkinter button inserting into sqlite table fails
Tkinter button inserting into sqlite table fails

Time:04-12

Hey I'm making a small tkinter app wchich uses sqlite as a database.
I'm constantly getting a error when trying to insert a row into the table. It happens when the button is pressed.

from tkinter import *
import sqlite3

pol=sqlite3.connect('/home/tom/Documents/VScode/bazalogowanie/baza.db') 
kurs=pol.cursor() 
kurs.execute('CREATE TABLE IF NOT EXISTS bazal (id INTEGER PRIMARY KEY AUTOINCREMENT, login TEXT, haslo, TEXT)')

##def zapis(login, haslo):
    ##pass



def odczyt():
        cala_baza = kurs.execute('SELECT * FROM bazal')
        for uzytkownik in cala_baza:
            print(uzytkownik)

def koniec():
    pol.commit()
    pol.close()
    exit()

root=Tk()  
root.geometry("400x400")
topFrame = Frame(root).pack()
bottomFrame = Frame(root).pack(side = "bottom")

Label(root, text="LOGIN").pack()
LOGIN=Entry(root)
LOGIN.pack()
root.title("BAZA LOGOWANIA")
Label(root, text="HASŁO").pack()
HASLO=Entry(root)
HASLO.pack()
login = LOGIN.get()
haslo = HASLO.get()
Button(root, text = "Login", command=lambda:kurs.execute(f'INSERT INTO bazal (login, haslo) VALUES ("{login}","{haslo})"')).pack()
Button(root, text="def log", command=lambda:odczyt()).pack()
Button(root, text= "zamknij", command=lambda:koniec()).pack()


root.mainloop()
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/home/tom/Documents/VScode/bazalogowanie/baza logowanie.py", line 38, in <lambda>
    Button(root, text = "Login", command=lambda:     kurs.execute(f'INSERT INTO bazal (login, haslo) VALUES ("{login}","{haslo})"')).pack()
sqlite3.OperationalError: incomplete input
Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.8/tkinter/__init__.py", line 1892, in __call__
    return self.func(*args)
  File "/home/tom/Documents/VScode/bazalogowanie/baza logowanie.py", line 38, in <lambda>
    Button(root, text = "Login", command=lambda:     kurs.execute(f'INSERT INTO bazal (login, haslo) VALUES ("{login}","{haslo})"')).pack()
sqlite3.OperationalError: incomplete input

I do not know where this error comes from can I ask for help?

CodePudding user response:

I got The solution there is a simple mistake in your code. Generally, This error show when you miss closing any parentheses in the code

Change

Button(root, text = "Login", command=lambda:kurs.execute(f'INSERT INTO bazal (login, haslo) VALUES ("{login}","{haslo}")')).pack()

To

Button(root, text = "Login", command=lambda:kurs.execute(f'INSERT INTO bazal (login, haslo) VALUES ("{login}","{haslo})"')

The Error is because you put double quote after parentheses there ("{login}","{haslo})").

You can see the same error solution on this link.

  • Related