使用Tkinter

时间:2017-04-10 20:10:51

标签: python-3.x tkinter sqlite

我目前正在创建一个登录系统,以便当用户点击登录按钮时,我的“员工”表格被搜索,如果在表格中找不到输入的ID,则会打印一条错误消息,但是,我一直收到此错误 -

“Tkinter回调中的异常 Traceback(最近一次调用最后一次):   文件“C:\ Users \ User \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ tkinter__init __。py”,第1699行,调用     return self.func(* args) 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()

1 个答案:

答案 0 :(得分:2)

GUI的编写方式是您不在回调中传递信息。相反,回调在执行时会从UI请求信息。

在您的情况下,我建议您删除login的参数,并修改login以在调用时获取信息。

例如:

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