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

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 get Entry and send the data to SQLite

    
asked by anonymous 11.08.2018 / 19:09

2 answers

0

Good morning! You can do it this way:

First you have to create a StringVar () for your entry, then you can add it 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,))
    
04.12.2018 / 14:00
2

Have you tried using the name.get () and age.get () attributes? 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 processing in this Send function.

I hope I have helped, I'm also playing with tkinter, but I do not know how to work with SQlite

    
16.08.2018 / 17:02