0

I'm working about login screen and user databases. I'm getting this error. Waiting for your advice.

Exception in Tkinter callback

Traceback (most recent call last): File "C:\Program Files\Python310\lib\tkinter_init_.py", line 1921, in call return self.func(*args)

File "D:\SoftwareLabCodes\AboutPython\project5 deneme\main.py", line 50, in login = Button(newUser, text="Register", bg="green", fg="white",command=lambda: insertToDb(usernameEntry.get(), passwordEntry.get()))

File "D:\SoftwareLabCodes\AboutPython\project5 deneme\main.py", line 25, in insertToDb im.execute("INSERT INTO userss (username , password, ) VALUES (?, ?)", (hashedUsername, hashedPassword)) sqlite3.OperationalError: near ")": syntax error

import sqlite3 as sql
from tkinter import *
import hashlib


db = sql.connect("usersDataBase")
im = db.cursor()

window = Tk()
window.geometry("720x480")
title = Label(text = "Login Screen")
title.place(relx=.4, rely=.15)

t ='CREATE TABLE IF NOT EXISTS userss (username VARCHAR (32), password VARCHAR(32), userID INTEGER PRIMARY KEY AUTOINCREMENT )'
im.execute(t)
db.commit()



def insertToDb(username, password):

    hashedUsername = username.encode("UTF-8")
    hashedPassword = hashlib.md5(password.encode("UTF-8")).hexdigest()

    im.execute("INSERT INTO userss (username , password, ) VALUES (?, ?)", (hashedUsername, hashedPassword))
    db.commit()
    print("User Created")
    resultStr.set("User Created")


def newAccountPage():
    global resultStr
    newUser = Frame(window)
    newUser.place(relwidth=0.9, relheight=0.9,relx=0., rely=0.3)

    usernameLabel = Label(newUser, text="Username :")
    usernameEntry = Entry(newUser, width=30)
    usernameLabel.place(relx=.25, rely=.05)
    usernameEntry.place(relx=.37, rely=.05)

    passwordLabel = Label(newUser, text="Password :")
    passwordEntry = Entry(newUser, width=30)
    passwordLabel.place(relx=.25, rely=.1)
    passwordEntry.place(relx=.37, rely=.1)

    resultStr = StringVar()
    result = Label(newUser, textvariable=resultStr)
    result.place(relx= .45, rely=.7)

    login = Button(newUser, text="Register", bg="green", fg="white",command=lambda: insertToDb(usernameEntry.get(), passwordEntry.get()))
    login.place(relx=.46, rely=.17)

    back = Button(newUser, text="Back", bg="red", fg="white", command= lambda: newUser.place_forget())
    back.place(relx=.3,rely=.4)




homePage = Frame(window)
homePage.place(relwidth=0.9, relheight=0.9,relx=0., rely=0.3)

usernameLabel = Label(homePage, text="Username :")
usernameEntry = Entry(homePage, width= 30)
usernameLabel.place(relx=.25 , rely=.05 )
usernameEntry.place(relx=.37 , rely=.05 )

passwordLabel = Label(homePage, text="Password :" )
passwordEntry = Entry(homePage, width= 30)
passwordLabel.place(relx=.25 , rely=.1)
passwordEntry.place(relx=.37 , rely=.1)

login = Button(homePage, text= "Login", fg="blue")
login.place(relx=.46, rely=.17)

register = Button(homePage, text= "Register", fg="green", command=newAccountPage)
register.place(relx=.45, rely=.25)



window.mainloop()

byhite
  • 39
  • 1
  • 3
  • 2
    Can you see that you have an extra comma after `password`? That's not allowed in SQL. Simple typo. – Tim Roberts Sep 06 '22 at 17:38
  • thank you so much . I was trying to solve this error for 2 hours. but still i can't hide password in register page – byhite Sep 06 '22 at 17:47
  • 1
    See https://stackoverflow.com/q/2416486/6950623 for creating a password field using Tkinter. (tl;dr: add `show="*"` argument to passwordLabel) – Sithell Sep 06 '22 at 17:57
  • Just FYI: "Exception in Tkinter callback Traceback (most recent call last)" is just the generic prefix to any error output from tkinter and doesn't actually indicate *what* the specific error is. – JRiggles Sep 06 '22 at 18:43

0 Answers0