Hello. I am very new to python, and I have been running through some problems. What I want to do is try to save data in which has been submitted from tkinter into a sqllite database. I have managed to save the data to which the individual type themselves, from the data entry, however I am struggling to save data from a combo box. Please help. So it is just Frame3 which I am struggling to save into a sqlite database
This is the code so far.
from tkinter import *
from tkinter import ttk
import tkinter as tk
import sqlite3
def show_frame(frame):
frame.tkraise()
def create():
conn=sqlite3.connect(‘database.db’)
c=conn.cursor()
c.execute(“CREATE TABLE IF NOT EXISTS users(id integer primary key autoincrement,name TEXT,surname TEXT,teamname TEXT,option1 TEXT,option2 TEXT,option3 TEXT,option4 TEXT)”)
conn.commit()
conn.close
create()
window=Tk()
window.geometry(‘400x400’)
window.resizable(False,False)
window.rowconfigure(0,weight=1)
window.columnconfigure(0,weight=1)
frame1=Frame(window)
frame2=Frame(window)
frame3=Frame(window)
frame4=Frame(window)
for frame in(frame1,frame2,frame3,frame4):
frame.grid(row=0,column=0,sticky=“nsew”)
#############frame 1 code
def savedata():
conn=sqlite3.connect(‘database.db’)
c=conn.cursor()
c.execute(‘Insert INTO users(name,surname,teamname) VALUES(?,?,?)’,(NameEntry1.get(),NameEntry2.get(),NameEntry3.get()))
conn.commit()
print(‘Saved’)
label1=Label(frame1,text=‘Individual Information’,font=(‘arial’,20,‘bold’),bg=‘grey’)
label1.pack(side=TOP)
Name=Label(frame1,text=‘Name’,font=(‘arial’,10,‘bold’))
Name.place(x=60,y=160)
NameEntry1=StringVar()
NameEntry1=ttk.Entry(frame1,textvariable=NameEntry1)
NameEntry1.place(x=160,y=160)
Surname=Label(frame1,text=‘Surname’,font=(‘arial’,10,‘bold’))
Surname.place(x=50,y=197)
NameEntry2=StringVar()
NameEntry2=ttk.Entry(frame1,textvariable=NameEntry2)
NameEntry2.place(x=160,y=200)
NickName=Label(frame1,text=‘NickName/TeamName’,font=(‘arial’,10,‘bold’))
NickName.place(x=10,y=230)
NameEntry3=StringVar()
NameEntry3=ttk.Entry(frame1,textvariable=NameEntry3)
NameEntry3.place(x=160,y=230)
button1=Button(frame1,text=‘Next’,command=lambda:show_frame(frame2))
button1.place(x=200,y=350)
button2=Button(frame1,text=‘Save Data’,command=savedata)
button2.place(x=90,y=350)
##############frame2 code
label2=Label(frame2,text=‘Decision’,font=(‘arial’,20,‘bold’),bg=‘grey’)
label2.pack(side=TOP)
button3=Button(frame2,text=‘Team’,command=lambda:show_frame(frame3))
button3.pack()
button4=Button(frame2,text=‘Individual’,command=lambda:show_frame(frame4))
button4.pack()
##############frame3
c=StringVar()
def savedata2():
conn=sqlite3.connect(‘database.db’)
c=conn.cursor()
c.execute(‘Insert INTO users(option1,option2,option3,option4) VALUES(?,?,?,?)’,(options1.get(),options2.get(),options3.get(),options4.get()))
conn.commit()
print(‘Saved’)
label3=Label(frame3,text=‘Pick 5 Team Event’,font=(‘arial’,20,‘bold’),bg=‘grey’)
label3.pack(side=TOP)
option1=Label(frame3, text=‘option1’,font=(‘arial’,12,‘bold’))
option1.place(x=20,y=100)
option2=Label(frame3, text=‘option2’,font=(‘arial’,12,‘bold’))
option2.place(x=20,y=150)
option3=Label(frame3, text=‘option3’,font=(‘arial’,12,‘bold’))
option3.place(x=20,y=200)
option4=Label(frame3, text=‘option4’,font=(‘arial’,12,‘bold’))
option4.place(x=20,y=250)
options1=[‘5 vs 5 football’,‘5 vs 5 rugby’,‘5 vs 5 baseball’]
cmb=ttk.Combobox(frame3,value=options1)
cmb.place(x=100,y=100)
options2=[‘5 by 100m relay’,‘5 by 100m hurdle’,‘5 by 100 mm swimming’]
cmb=ttk.Combobox(frame3,value=options2,)
cmb.place(x=100,y=150)
options3=[‘5 vs 5 math competion’,‘5 vs 5 countdown’,‘5 vs 5 spelling bee’]
cmb=ttk.Combobox(frame3,value=options3)
cmb.place(x=100,y=200)
options4=[‘Tennis’,‘Table Tennis’,‘Badminton’]
cmb=ttk.Combobox(frame3,value=options4)
cmb.place(x=100,y=250)
buttonF3=Button(frame3,text=‘Next’,command=lambda:show_frame(frame1))
buttonF3.place(x=200,y=350)
button6=Button(frame3,text=‘Save Data’,command=savedata2)
button6.place(x=90,y=350)
show_frame(frame1)
window.mainloop()