sqlite3.InterfaceError:错误绑定参数0可能不受支持的类型。登录pag

2024-04-26 07:35:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图建立一个登录页面,并已接近这个错误。我现在正在让程序检查数据库文件中的用户ID,以便他们可以登录,但我得到了这个错误:

sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

几个小时后我似乎无法让它工作,所以我来这里寻求帮助。在

导致问题的函数是:login_verify() 导致错误的行已用注释标记

错误图片:

enter image description here

数据库图片:

enter image description here

from tkinter import *
import sqlite3

root = Tk()
root.geometry('500x500')
root.title("Bank Portal")

Fullname=StringVar()
Email=StringVar()
Gender=StringVar()
c=StringVar()
var1= IntVar()
ID=IntVar()

def main_screen_destroy():

   root.destroy()
   login()

def login_screen_destroy():

   login.destroy()
   activity()





def activity():

   activity = Tk() # Line that is creating error
   activity.geometry('500x350')
   activity.title("Bank Portal")

   label_9 = Label(activity, text="Account Transaction",width=20,font=("bold", 20))
   label_9.place(x=70,y=53)

   Button(activity, text='Balance',width=20,bg='blue',fg='white',command=quit).place(x=180,y=250)
   Button(activity, text='Deposit',width=20,bg='blue',fg='white',command=quit).place(x=180,y=280)
   Button(activity, text='Withdraw',width=20,bg='blue',fg='white',command=quit).place(x=180,y=310)

   activity.mainloop()



def login():  # New page 

   login = Tk() # Line that is creating error
   login.geometry('500x350')
   login.title("Bank Portal")

   label_5 = Label(login, text="Account Login",width=20,font=("bold", 20))
   label_5.place(x=70,y=53)

   label_6 = Label(login, text="ID Number",width=20,font=("bold", 10))
   label_6.place(x=80,y=130)

   entry_7 = Entry(login,textvar=ID)
   entry_7.place(x=220,y=130)

   label_8 = Label(login, text="Email ",width=20,font=("bold", 10))
   label_8.place(x=82,y=180)

   entry_8 = Entry(login,textvar=Email)
   entry_8.place(x=220,y=180)

   Button(login, text='Submit',width=20,bg='blue',fg='white',command=login_verify).place(x=180,y=250)

   login.mainloop()


def login_verify(): 

   global ID

   with sqlite3.connect('Form.db')as db:

      cursor=db.cursor()
      finduser=('SELECT * FROM Users WHERE ID = ?')
      cursor.execute(finduser,(ID,)) #line causing error


   if cursor.fetchall():
      login_screen_destroy()

   else:
      login.destroy()



def database():

   name1=Fullname.get()
   email=Email.get()
   gender=Gender.get()
   country=c.get()

   iD=ID.get()

   conn = sqlite3.connect('Form.db')

   with conn:
      cursor=conn.cursor()
   cursor.execute('CREATE TABLE IF NOT EXISTS Users (Fullname TEXT,Email TEXT,Gender TEXT,country TEXT, ID TEXT)')
   cursor.execute('INSERT INTO Users (FullName,Email,Gender,country,ID) VALUES(?,?,?,?,?)',(name1,email,gender,country,iD))
   conn.commit()


label_0 = Label(root, text="Account Registration",width=20,font=("bold", 20))
label_0.place(x=90,y=53)

label_1 = Label(root, text="Full Name",width=20,font=("bold", 10))
label_1.place(x=80,y=130)

entry_1 = Entry(root,textvar=Fullname)
entry_1.place(x=240,y=130)

label_1 = Label(root, text="ID Number",width=20,font=("bold", 10))
label_1.place(x=80,y=160)

entry_1 = Entry(root,textvar=ID)
entry_1.place(x=240,y=160)

label_2 = Label(root, text="Email Address",width=20,font=("bold", 10))
label_2.place(x=68,y=210)

entry_2 = Entry(root,textvar=Email)
entry_2.place(x=240,y=210)

label_4 = Label(root, text="Gender",width=20,font=("bold", 10))
label_4.place(x=70,y=260)

list2 = ['Male','Female','Prefer not to say'];

droplist=OptionMenu(root,Gender, *list2)
droplist.config(width=15)
Gender.set('Select your gender') 
droplist.place(x=240,y=260)

label_4 = Label(root, text="Country",width=20,font=("bold", 10))
label_4.place(x=70,y=310)

list1 = ['Australia','India','England','USA','New Zealand','China','Japan','Singapore','Hong Kong','North Korea','South Korea','Germany','Italy','Greece','France'];

droplist=OptionMenu(root,c, *list1)
droplist.config(width=15)
c.set('Select your country') 
droplist.place(x=240,y=310)

Button(root, text='Submit',width=20,bg='brown',fg='white',command=database).place(x=180,y=380)
Button(root, text='Login',width=20,bg='brown',fg='white',command=main_screen_destroy).place(x=180,y=420)

root.mainloop()

Tags: textidemailloginplacerootactivitywidth
1条回答
网友
1楼 · 发布于 2024-04-26 07:35:37

错误消息指出ID的类型不受支持。
您定义了ID = IntVar(),因此请尝试使用get方法:

cursor.execute(finduser,(ID.get(),))

相关问题 更多 >