В этом коде значение флажка хранится, но в форме 1 0, но я хочу сохранить строку
Я пытался сохранить флажок через "INSERT INTO", но после того, как метод .get () срабатывает, записывается ноль и единица в базу данных, как я могу решить эту проблему?
При запуске программы она записывает нули в переменную, хотя если флажок активен.
Код
from tkinter import *
import tkinter as tk
import sqlite3
root= tk.Tk()
root.resizable(0, 0)
root.title("Registration Form")
reg = Frame(root)
# calc.grid()
Fullname = StringVar()
Email = StringVar()
def database():
name = Fullname.get()
email = Email.get()
gender = var.get()
branch = c.get()
prog = var1.get()+var2.get()+var3.get()
conn = sqlite3.connect('Form.db')
with conn:
cursor = conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Student ( Fullname TEXT,Email TEXT,Gender TEXT,Branch TEXT,Programming TEXT)')
cursor.execute('INSERT INTO Student (Fullname,Email,Gender,Branch,Programming) VALUES(?,?,?,?,?)',(name,email,gender,branch,prog))
conn.commit()
canvas1 = tk.Canvas(root, width = 500, height = 500, relief = 'raised', bg="white")
canvas1.pack()
label1 = tk.Label(root, text='Registration Form')
label1.config(font=("bold", 18),bg="white")
canvas1.create_window(250, 30, window=label1)
label2 = tk.Label(root, text='Fullname :')
label2.config(font=('helvetica',14),bg="white")
canvas1.create_window(65, 90, window=label2)
entry1 = tk.Entry(root, textvar = Fullname, font = (14), borderwidth=2, width = 35)
canvas1.create_window(320, 90, window=entry1)
label3 = tk.Label(root, text='E-mail :')
label3.config(font=('helvetica',14),bg="white")
canvas1.create_window(65, 140, window=label3)
entry2 = tk.Entry (root, textvar = Email, font = (14), borderwidth=2, width = 35)
canvas1.create_window(320, 140, window=entry2)
label4 = tk.Label(root, text='Gender :')
label4.config(font=('helvetica',14),bg="white")
canvas1.create_window(65, 190, window=label4)
var = StringVar()
rd1 = tk.Radiobutton(root ,text="Male" ,padx = 5, variable = var, value = "Male")
rd1.config(font=('helvetica',14),bg="white")
canvas1.create_window(200,190, window = rd1)
rd2 = tk.Radiobutton(root ,text="Female" ,padx = 20, variable = var, value = "Female")
rd2.config(font=('helvetica',14),bg="white")
canvas1.create_window(300,190, window = rd2)
label5 = tk.Label(root, text='Branch :')
label5.config(font=('helvetica',14),bg="white")
canvas1.create_window(65, 240, window=label5)
list1 = ['CSE','MECH','ENTC','CIVIL']
c=StringVar()
droplist = tk.OptionMenu(root,c,*list1)
droplist.config(font=('helvetica',14),bg="white",width = 27)
c.set('Select your branch')
canvas1.create_window(320,240, window = droplist)
label6 = tk.Label(root, text='Programming :')
label6.config(font=('helvetica',14),bg="white")
canvas1.create_window(65, 290, window=label6)
var1 = StringVar()
cb1 = tk.Checkbutton(root, text="Python", variable=var1)
cb1.config(font=('helvetica',14),bg="white")
canvas1.create_window(200, 290, window=cb1)
var2 = StringVar()
cb2 = tk.Checkbutton(root, text="Java", variable=var2)
cb2.config(font=('helvetica',14),bg="white")
canvas1.create_window(300, 290, window=cb2)
var3 = StringVar()
cb3 = tk.Checkbutton(root, text="C", variable=var3)
cb3.config(font=('helvetica',14),bg="white")
canvas1.create_window(400, 290, window=cb3)
button1 = tk.Button(text='Submit',command=database, bg='black', fg='white', font=('helvetica', 12, 'bold'))
canvas1.create_window(250, 350, window=button1)
def iExit():
iExit = tkinter.messagebox.askyesno("Scientific Calculator","Do you want to exit ?")
if iExit>0:
root.destroy()
return
def Data():
root.resizable(width=False, height=False)
root.geometry("1000x500+0+0")
def Form():
root.resizable(width=False, height=False)
root.geometry("500x500+0+0")
menubar = Menu(reg)
filemenu = Menu(menubar, tearoff = 0)
menubar.add_cascade(label = 'File', menu = filemenu)
filemenu.add_command(label = "Form", command = Form)
filemenu.add_command(label = "Data", command = Data)
filemenu.add_separator()
filemenu.add_command(label = "Exit",command = iExit)
root.config(menu=menubar)
mainloop()