2017-04-10 36 views
2

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

的錯誤是不言自明:你定義'login'需要一個參數,但按鈕是不是傳遞一個參數。 –

+0

每次我嘗試傳遞一個參數 - sqlite3.InterfaceError:錯誤綁定參數0 - 可能不支持的類型。 –

回答

2

圖形用戶界面通常編寫的方式是,您不會在回調中傳遞信息。相反,該回調在執行時會從UI請求信息。

在你的情況下,我建議你刪除參數login,並修改login來獲取調用時的信息。

例如:

def login(): 
    id = eID.get() 
    ... 
+0

現在完美工作,非常感謝您的幫助! –