我目前正在创建一个登录系统,以便当用户单击登录按钮时,我的“员工”表将被搜索,如果在表中找不到输入的ID,则会显示错误消息被打印出来,不过,我不断收到此错误 -对Tkinter按钮执行SQL搜索
“在Tkinter的回调 回溯异常(最新最后调用): 文件” C:\用户\用户\应用程序数据\本地\程序\ Python的\ Python36-32 \ lib \ tkinter__init __。py“,行1699,在调用 返回self.func(*参数) TypeError:login()缺少1需要的位置参数:'id'”
from tkinter import *
import sqlite3
global employeeIDVar
win = Tk()
img = PhotoImage(file = 'download_1_.gif')
imgLbl = Label (win, image = img)
frame1=Frame(win)
frame1.pack()
Label(frame1, text="Welcome to the system!",font=('Comic Sans MS',18)).grid(row=0, column=1)
Label(frame1, text="EmployeeID").grid(row=1, column=0, sticky=W)
employeeIDVar=IntVar(win)
eID= Entry(frame1, textvariable=employeeIDVar)
eID.grid(row=1,column=1,sticky=W)
frame2 = Frame(win)
frame2.pack()
b1= Button(frame2, text=" Login ")
b2= Button(frame2, text=" Quit ")
b1.pack(side=LEFT); b2.pack(side=LEFT)
def login(id):
with sqlite3.connect("comicBookGuys.db") as db:
cursor = db.cursor()
cursor.execute ("select employeeID, numberOfSales, salesTarget from Employee where employeeID=?", (id,))
dataFound = cursor.fetchone()
return dataFound
if not dataFound:
messagebox.showinfo("No such employeeID found! Try again.")
def logEnd():
exit()
b1.configure(command=login)
b2.configure(command=logEnd)
win.mainloop()
win.mainloop()
的错误是不言自明:你定义'login'需要一个参数,但按钮是不是传递一个参数。 –
每次我尝试传递一个参数 - sqlite3.InterfaceError:错误绑定参数0 - 可能不支持的类型。 –