正在尝试将spinbox中的值保存到我的数据库中。这是我代码的一部分。你知道吗
numericupdownLL = tk.Spinbox(self, from_=0, to=300)
numericupdownLL.pack()
def saveDate(title):
vLL = int(numericupdownLL.get()) ## convert to int because output of spinbox= str and database=int
c.execute("UPDATE settings SET ll=? WHERE name=?",(vLL, title))
conn.commit()
buttonSave = tk.Button(self, text='save', command=saveData(something)
buttonSave.pack()
现在我没有得到任何错误,但是代码总是将一个0写入我的db,而不是spinbox的值。你知道吗
你知道吗?你知道吗
为了使解释一致,我将更正代码中的拼写错误
两个注意事项:
让我们开始:
首先要注意的是,您只调用函数一次,而不是每次单击按钮。这是因为不是传递函数,而是传递一个None,这是函数调用的返回。所以要解决这个问题,你应该去掉括号,把函数作为回调传递
更正后,每次单击该按钮时,都会出现一个异常,告诉您函数需要1个参数,并传递0。 此异常是由于
saveData
函数中的title
参数引起的,因此如果希望将某个参数作为参数传递,则需要返回一个回调,该回调在内部使用该参数,但不接受任何参数:所以最后的代码应该是这样的:
总结:
something
,您必须检索一个没有参数的函数,并将该变量用作闭包。你知道吗如果代码的任何部分不适合你,请告诉我!你知道吗
相关问题 更多 >
编程相关推荐