我正在向tKinter GUI窗口中馈入一些数据,并希望在单击“提交”按钮时该数据将存储在SQLite数据库中,并且GUI在窗口中显示表记录,但它似乎没有将值传递给db。
我几乎完成了代码,但没有传递值。我已分担了代码的麻烦部分以供参考。
这是我的代码
#Date & Month selection
Month_list = ['Jan','Feb','Mar','April','May','June','Jul','Aug','Sep','Oct','Nov','Dec']
Date_list = list(range(1,32))
year_list = list(range(2019,2031))
dt_mn_yr=StringVar()
Jirano=StringVar()
Time=StringVar()
Remark=StringVar()
def drop_down(list_name,set_name,grow,gcolumn):
"""Function will show drop down selection"""
c=StringVar()
droplist=OptionMenu(window,c, *list_name)
droplist.config(width=5)
c.set(set_name)
droplist.grid(row=grow,column=gcolumn)
return c
def Database():
"""Connect to DB,Insert & Read the records"""
d= dt.get()
m= mn.get()
y = yr.get()
Date = str(d)+"-"+str(m)+"-"+str(y)
jira_no = Jirano.get()
time_mins = Time.get()
remark = Remark.get()
#Result Display window
display_windows = Label(window,text="" ,font=("Arial Bold", 10))
display_windows.grid(row=900,column=20)
try:
conn = sqlite3.connect("AutomationDB.db")
except:
return "DB connection error"
#Creating table
conn.execute("CREATE TABLE IF NOT EXISTS TimeTrackerTable (Date TEXT,Jirano TEXT,Time TEXT,Remark TEXT)")
#Inerting records
conn.execute("INSERT INTO TimeTrackerTable (Date,Jirano,Time,Remark) VALUES (?,?,?,?)",(Date,jira_no,time_mins,remark))
conn.commit()
#Reading the records
cursor= conn.execute("select * from TimeTrackerTable")
for i in cursor:
display_windows.configure(text=i)
conn.close()
dt=drop_down(Date_list,'Date',400,20)
mn=drop_down(Month_list,'Month',400,21)
yr=drop_down(year_list,'Year',400,22)
#dt_mn_yr = dt+"-"+mn+"-"+yr
#dt_mn_yr = str(dt_mn_yr)
#Input JIRA number
jira_no = Entry(window,width = 15,textvar=Jirano)
jira_no.grid(row=450,column =20 )
jira_no = str(jira_no)
#Input Time
time_mins = Entry(window,width = 15,textvar=Time)
time_mins.grid(row=500,column =20)
time_mins = str(time_mins)
#Input Remark
remark = Entry(window,width = 30,textvar=Remark)
remark.grid(row=550,column =20)
remark = str(remark)
#Submit button
Button(window, text='Submit',width=15,bg='brown',fg='white',COMMAND = Database()).grid(row=750,column=20)
window.mainloop()
货币我不使用显示当前值的选择值。我的要求是在提交按钮后查看数据库选择查询结果。有什么建议吗?