[英]Saving a tkinter output to an sqlite3 database
I'm fairly new to programming and I'm trying to save the input from a tkinter entry box to a field in a sqlite database. 我对编程还很陌生,我正在尝试将tkinter输入框的输入保存到sqlite数据库中的字段中。 However, however I try to do so, it always saves as a variation of PY_VAR(number) or simply prints as {}.
但是,无论如何,我总是将其保存为PY_VAR(number)的变体,或仅打印为{}。 This is the relevant section of code (the SQL queries are all valid in context of my database).
这是代码的相关部分(SQL查询在数据库上下文中均有效)。 How would I go about rectifying this so an entry input would save to the relevant column in the SQL database?
我将如何纠正此问题,以便将输入条目保存到SQL数据库中的相关列? `
`
enteredName = StringVar()
nameEntry = Entry(mainFrame,textvariable = enteredName)
nameEntry.grid(row = 3 + recordNo,column=4)
c.execute("SELECT name FROM purchases WHERE productID = (?)",
(recordNo,))
savedName = c.fetchone()
conn.commit()
if savedName != "":
nameEntry.insert(1,savedName)
nameToSave=str(enteredName.get())
c.execute("UPDATE purchases SET name = ? WHERE productID = ?",
(nameToSave,recordNo))
conn.commit()
Change the .get()
to .get("1.0", "end-1c")
. 将
.get()
更改为.get("1.0", "end-1c")
。 The 1.0
makes it be read from the first character and end-1c
makes it read till the end of the text box. 1.0
使它从第一个字符开始读取,而end-1c
使它直到文本框的末尾读取。 The 1c
part removes the extra newline the text box will add. 1c
部分删除了文本框将添加的多余换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.