我的python程序工作不正常,它与提交按钮有关,它给我一个错误,说:
TypeError: 'str' object is not callable
请帮帮我。以下是代码中不起作用的部分:
def submit():
g_name = ent0.get()
g_surname = ent1.get()
g_dob = ent2.get()
g_tutorg = ent3.get() #Gets all the entry boxes
g_email = ent4.get()
cursor = db.cursor()
sql = '''INSERT into Students, (g_name, g_surname, g_dob, g_tutorg, g_email) VALUES (?,?,?,?,?)'''
cursor.execute(sql (g_name, g_surname, g_dob, g_tutorg, g_email))
#Puts it all on to SQL
db.commit()
mlabe2=Label(mGui,text="Form submitted, press exit to exit").place(x=90,y=0)
我不确定您还需要什么,下面是创建表的SQL部分的其余部分
cursor = db.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS Students(
StudentID integer,
Name text,
Surname text,
DOB blob,
Tutor_Grop blob,
Email blob,
Primary Key(StudentID));
""") #Will create if it doesn't exist
db.commit()
我已经试了这么久,找不到解决这个问题的办法,所以如果你能帮忙,那就太好了,谢谢
您没有正确传递变量的值。您调用
cursor.execute(sql())
的方式使解释器认为它是一个函数。你知道吗您需要正确格式化
sql
字符串:sql = '''INSERT into Students, ({}, {}, {}, {}, {}) VALUES (?,?,?,?,?)'''.format(g_name, g_surname, g_dob, g_tutorg, g_email)
然后使用:
cursor.execute(sql)
编辑: 或者您可能需要传递一个包含数据的元组:
sql = '''INSERT into Students VALUES (?,?,?,?,?)'''
'data = (g_name, g_surname, g_dob, g_tutorg, g_email)
然后使用cursor.execute(sql, data)'
这取决于这些值实际上是什么,如果没有看到数据库,我就说不出来。你知道吗
你的问题可能是:
试着这样改变:
编辑:
在我的简单应用程序中,我使用以下代码调用SQLite插入:
它工作正常。你知道吗
相关问题 更多 >
编程相关推荐