我的Tkinter / Sqlite Python应用程序出现问题

时间:2017-02-21 20:51:32

标签: sqlite python-3.x tkinter

我正处于编写通讯录应用程序的初级阶段。当我运行应用程序并输入第一个姓氏并点击添加时,我收到一条错误消息。没有任何getts添加到数据库。

以下是错误消息:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__
    return self.func(*args)
  File "address.py", line 13, in addName
    (last_name, first_name))
sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.

这是我的代码:

from tkinter import *
from tkinter import ttk
import sqlite3

conn = sqlite3.connect('address.db')
c = conn.cursor() 
c.execute('''CREATE TABLE IF NOT EXISTS address (lastName TEXT, firstName TEXT )''') 
conn.commit 

def addName(event):

    c.execute("INSERT INTO address (lastName, firstName) VALUES (?,?)",
            (last_name, first_name))

    conn.commit()

root = Tk()
root.title('Address Book')
Label(root, text='First Name').grid(row=0, sticky=W, padx=4)
first_name = Entry(root)
first_name.grid(row=0, column=1, sticky=E, pady=4)

Label(root, text='Last Name').grid(row=1, sticky=W, padx=4)
last_name = Entry(root).grid(row=1, column=1, sticky=E, pady=4)

getNameButton = Button(root, text='Add')
getNameButton.bind('<Button-1>', addName)
getNameButton.grid(row=3, column=1, sticky=E)

root.mainloop()

TIA,

加布里埃尔

1 个答案:

答案 0 :(得分:0)

我认为这可能会有所帮助: c.execute('INSERT INTO地址(姓氏,名字)VALUES(?,?)',([last_name,first_name]))