Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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应用程序未在数据库中创建条目_Python_Tkinter - Fatal编程技术网

Python应用程序未在数据库中创建条目

Python应用程序未在数据库中创建条目,python,tkinter,Python,Tkinter,我的代码有问题。这段代码应该在数据库中创建条目,但它不起作用。你知道我哪里出错了吗? 或者,在Excel中创建新条目并将此文件保存在C驱动器中更容易吗?每次输入数据时,它都会更新,如果是,那么它应该是什么样子? 也许你还有其他建议,我应该改变什么 from tkinter import * import sqlite3 root = Tk() root.geometry('600x600') root.title("TOOL") Germany_other_team = StringVar(

我的代码有问题。这段代码应该在数据库中创建条目,但它不起作用。你知道我哪里出错了吗? 或者,在Excel中创建新条目并将此文件保存在C驱动器中更容易吗?每次输入数据时,它都会更新,如果是,那么它应该是什么样子? 也许你还有其他建议,我应该改变什么

from tkinter import *
import sqlite3

root = Tk()
root.geometry('600x600')
root.title("TOOL")

Germany_other_team = StringVar()
Austria_other_team = StringVar()
Germany_self_solved = StringVar()
Austria _self_solved = StringVar()
Assigned_to_other_colleague = StringVar()
Reopened_by_user = StringVar()
SCTASK = StringVar()



def database():
   de_other= Germany_other_team.get()
   at_other= Austria_other_team.get()
   de_self= Germany_self_solved.get()
   at_self= Austria_self_solved.get()
   other_coll=Assigned_to_other_colleague.get()
   reopen_user=Reopened_by_user.get()
   task=SCTASK.get()
   conn = sqlite3.connect('Form.db')
   with conn:
      cursor=conn.cursor()
      cursor.execute('CREATE TABLE IF NOT EXISTS Incident (Germany (to other team) TEXT, Austria(to other team) TEXT, Germany (self solved) TEXT, Austria (self solved) TEXT,Assigned to other colleague TEXT, Re-opened by user TEXT, SCTASK TEXT)')
      cursor.execute('INSERT INTO Incident (Germany (to other team), Austria (to other team), Germany (self solved), Austria (self solved),Assigned to other colleague, Re-opened by user,SCTASK) VALUES(?,?,?,?,?,?,?)',(de_other,at_other,de_self,at_self,other_coll,reopen_user,task,))
      conn.commit()



label_0 = Label(root, text="TOOL",width=20,font=("bold", 20))
label_0.place(x=90,y=53)


label_1 = Label(root, text="Germany (to other team)",width=20,font=("bold", 10))
label_1.place(x=80,y=130)

entry_1 = Entry(root)
entry_1.place(x=240,y=130)

label_2 = Label(root, text=" Austria (to other team)",width=20,font=("bold", 10))
label_2.place(x=68,y=180)

entry_2 = Entry(root)
entry_2.place(x=240,y=180)

label_3 = Label(root, text=" Germany (self solved)",width=20,font=("bold", 10))
label_3.place(x=70,y=230)

entry_3 = Entry(root)
entry_3.place(x=235,y=230)

label_4 = Label(root, text=" Austria (self solved)",width=20,font=("bold", 10))
label_4.place(x=60,y=280)

entry_4 = Entry(root)
entry_4.place(x=240,y=280)

label_5 = Label(root, text="Assigned to other colleague",width=20,font=("bold", 10))
label_5.place(x=70,y=330)

entry_5 = Entry(root)
entry_5.place(x=235,y=330)

label_6 = Label(root, text="Re-opened by user",width=20,font=("bold", 10))
label_6.place(x=70,y=380)

entry_6 = Entry(root)
entry_6.place(x=240,y=380)

label_7 = Label(root, text="SCTASK",width=20,font=("bold", 10))
label_7.place(x=115,y=430)

entry_7 = Entry(root)
entry_7.place(x=240,y=430)


Button(root, text='Submit',width=20,bg='brown',fg='white').place(x=130,y=480)

root.mainloop()


当您使用Tkinter的get函数时,据我所知,get()只适用于条目和文本小部件,您正在尝试从标签获取文本

要从标签中获取值,可以使用
cget
方法,该方法可用于获取配置选项的值

例如:

l = Label(text = "How are you?")
...
de_other = l.cget("text")
这将使标签中设置为文本的内容成为其他内容


您的程序可能正在向数据库中输入某些内容,因为没有错误,在这种情况下,它将什么也不输入。

您应该将
光标。执行(…)
conn.commit()
放在
with conn:
块中。@acw1668我现在确实在我的代码中进行了编辑,但它仍然没有创建此数据库文件。字段名可能无效。请尝试用“”。@JuliusC“它不工作。”:这没有帮助,您的问题和详细解释并显示任何错误消息。您的代码不会修改那些
StringVar
s,并且
数据库()
从未被调用。