Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/MySQL-通过Tkinter将数据插入表中_Python_Mysql_Tkinter - Fatal编程技术网

Python/MySQL-通过Tkinter将数据插入表中

Python/MySQL-通过Tkinter将数据插入表中,python,mysql,tkinter,Python,Mysql,Tkinter,我试图通过图形界面将数据插入表中,但出现以下错误: 错误 代码 按钮在不带参数的情况下运行函数,因此不能使用参数声明函数 def submit(): 它应该可以解决错误消息的问题,但您仍然无法获取值 您的StringVar()在submit()中无效。您应该直接在SQL中使用条目 mysql_submit = ("INSERT INTO novo VALUES (NULL, {}, {}, {})", (e_nome.get(), e_idade.get(), e_cpf.get())) 但

我试图通过图形界面将数据插入表中,但出现以下错误:

错误

代码


按钮
在不带参数的情况下运行函数,因此不能使用参数声明函数

def submit():
它应该可以解决错误消息的问题,但您仍然无法获取值

您的
StringVar()
submit()
中无效。您应该直接在SQL中使用条目

mysql_submit = ("INSERT INTO novo VALUES (NULL, {}, {}, {})", (e_nome.get(), e_idade.get(), e_cpf.get()))
但是您应该将它直接放在
execute
中,因为它期望
QUERY
作为第一个参数,而值作为第二个参数。元组
mysql\u submit
将被视为一个参数,而不是两个

cursor.execute("INSERT INTO novo VALUES (NULL, {}, {}, {})", (e_nome.get(), e_idade.get(), e_cpf.get()))

submit
需要参数,因此您需要
command=lambda:submit(…参数…
或从定义中删除参数
def submit():
submit()
中,您应该使用
nome=e_nome.get()
条目中获取值。使用nome=StringVar()
是没有用的。其他值也是如此。
mysql_submit = ("INSERT INTO novo VALUES (NULL, {}, {}, {})", (e_nome.get(), e_idade.get(), e_cpf.get()))
cursor.execute("INSERT INTO novo VALUES (NULL, {}, {}, {})", (e_nome.get(), e_idade.get(), e_cpf.get()))