Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9172437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:20:45+00:00 2026-06-17T16:20:45+00:00

I am coding a small program to simply save text data and integer data

  • 0

I am coding a small program to simply save text data and integer data
into an SQLite3 database.

I have created the db called test.db with the following code:

con = sqlite3.connect('test.db')
cur = con.cursor()
cur.execute('drop table if exists data')
cur.execute('create table data(t1 TEXT, i1 INT)')
con.commit()
print('DB created')

The problem is when I run it it tells
me that the cur.execute line requires strings as parameters, but I have already defined text1 as string with StringVar.

from tkinter import *
from tkinter import ttk
import sqlite3

def savedata(text1, int1):
    con = sqlite3.connect('test.db')
    cur = con.cursor()
    cur.execute(('INSERT INTO data (t1, i1) VALUES (?,?)', (text1, int1)))
    con.commit()
    print('record inserted in data')

root = Tk()
root.title("Little Program To Save Data")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column = 0, row = 0, sticky = (N,W,E,S))
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)

text1 = StringVar()
text_entry = ttk.Entry(mainframe, width = 20, textvariable=text1)
text_entry.grid(column = 2, row = 1, sticky = (N,W,E,S))

int1 = IntVar()
int_entry = ttk.Entry(mainframe, width = 20, textvariable=int1)
int_entry.grid(column = 2, row = 2, sticky = (N,W,E,S))

ttk.Button(mainframe, text = "Save!", command=savedata(text1, int1)).grid(column = 3, row = 3, sticky = (W, E))

for child in mainframe.winfo_children(): 
    child.grid_configure(padx = 5, pady = 5)

root.mainloop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:20:46+00:00Added an answer on June 17, 2026 at 4:20 pm

    The code doesn’t work because StringVar and IntVar are not the typical Python objects str and int, they actually represent Tcl variables which you might happen to set to contain values that can be classified either as string or integer.

    The first thing you need to do is change savedata(text1, int1) to savedata(text1.get(), int1.get()) so you actually obtain the values stored in them. Secondly, the way you define the value for the command parameter in the Button widget is wrong because you are executing it instead of passing a function to be executed when you actually click the button. That is fixed by changing that part to command = lambda: savedata(...). Thirdly, you are calling

    cur.execute(('INSERT INTO data (t1, i1) VALUES (?,?)', (text1, int1)))
    

    but that will certainly fail, because you are passing a tuple to execute, what you actually want is:

    cur.execute('INSERT INTO data (t1, i1) VALUES (?,?)', (text1, int1))
    

    Now your code works, but there is no need to use Tcl variables here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a small problem. I am coding a program that displays the
I have created a small program to see if I'm as proficient in Python
I have a small Python program consisting of very few modules (about 4 or
I was recently coding a small java program (as design for an 8086 Assembler
I was tasked with creating a small application for college, and have created a
I am building a small program to retrieve data from the market and chart
I tried the following two approaches. When I test it in a small program,
I'm coding a small program to time and show, in a ordered fashion, my
My son asked me if I could write a small program to have a
After running this small program: #!/usr/bin/env python2.7 # -*-coding:utf-8 -* a = 1 b

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.