Q:

Problem with checkbox and database in tkinter

I tried to save the checkbox through "INSERT INTO", but after the .get () method is triggered, zero is constantly written to the database, how I can solve this problem? 
When starting the program, it writes two zeros to the variable, although if the checkbox is active, one must be written. 
Code:
var1 = IntVar()

c1 = Checkbutton(text="First", variable=var1, onvalue=1, offvalue=0)

c1.pack(anchor=W)

var2 = IntVar()

c2 = Checkbutton(text="Second", variable=var2, onvalue=1, offvalue=0)

c2.pack(anchor=W)

conn = sqlite3.connect("MyDB.db")

cursor = conn.cursor()

conn.execute("INSERT INTO TestDB VALUES (:var1, :var2)", {'var1': var1.get(), 'var2': var2.get()})

conn.commit()

conn.close()

No console errors.  Values into DB(zero, in any case, it doesn’t matter if the checkbox is active or not) - https://ibb.co/B6jBDTV

A:

I make a function that will get variable of checkbox and function that write this variable into my DB, this is code: 
root = Tk()
root.title("getcheck")
root.geometry("350x250")

def create_DB():
    conn = sqlite3.connect("MyDB.db")
    cursor = conn.cursor()
    conn.execute("""CREATE TABLE IF NOT EXISTS TestDB (var1 integer, var2 integer)""")
    conn.commit()
    conn.close()

def get_var():
    conn = sqlite3.connect("MyDB.db")
    cursor = conn.cursor()
    conn.execute("INSERT INTO TestDB VALUES (:var1, :var2)", {'var1': var1.get(), 'var2': var2.get()})
    conn.commit()
    conn.close()

btn = Button(root, text = "create_db", command = create_DB).pack(anchor = W)
btn1 = Button(root, text = "get value", command = get_var).pack(anchor = W)

var1 = IntVar()
Checkbutton(root, text = "first var", variable = var1).place(x = 75,y = 1)

var2 = IntVar()
Checkbutton(root, text = "second var", variable = var2).place(x = 120, y = 28)

root.mainloop()

