我目前正在創建一個登錄系統,以便當用戶單擊登錄按鈕時,我的「員工」表將被搜索,如果在表中找不到輸入的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 - 可能不支持的類型。 –