How do I take data from an Entry and add it to the Database (sqlite3)

Asked

Viewed 443 times

0

from tkinter import *

jan = Tk()
jan.title("Dados")
jan.geometry("200x200+250+100")

label = Label(jan, text="Nome:")
label.grid(row=0, column=0)

nome = Entry(jan, width=25)
nome.grid(row=0,column=1)

label2 = Label(jan, text="Idade:")
label2.grid(row=1, column=0)

idade = Entry(jan, width=25)
idade.grid(row=1,column=1)

jan.mainloop()

I wanted to take Entry and send the data to Sqlite

  • Please people, I really need the help of you, who can give a little help pfv manifests there

2 answers

2

You tried to use the attributes get name.() and get age.()? It will return the contents of Entry. You can use something like enviar = Button(jan, text='Enviar', command=lambda e: enviar(nome.get(), idade.get())); And do all the treatment in this Send function.

I hope I helped, I’m also playing with Tkinter, but I don’t know how to work with Sqlite

0


Good morning! You can do it this way :

First you have to create a Stringvar() for your entry, then Voce can add to the database

creating the Stringvar()

var1 = StringVar()

Creating the Entry

nome = Entry(jan, width=25, textvariable = var1)
nome.grid(row=0,column=1)

Adding to the database

var2 = var1.get()

cur = c.execute('INSERT INTO nomedatabela(colunaQueDesejaAdicionar) VALUES (?)',(var2,))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.