0
I am studying, on my own Sqlite, I already bought some courses, but I need a help.
Objective: I would like to save the user typed fields in the database and then clear the same fields to allow new data entries.
The program is a window with a field called email and another field called password and a save button.
When you click the save button, three columns must be saved in the database (auto-increment id, email, password)
The code below shows only the window code, Below, you will have the code of the module users, where I put the code Sqlite.
from tkinter import *
import usuarios
janela = Tk()
janela.title("Cadastro de usuário")
janela["bg"] = "lightblue"
janela.geometry('300x200+700+400')
rotulo = Label(janela,
font="Arial 18 bold",
text='Cadastro de usuário',
bg="lightblue")
rotulo.place(x=25, y=10)
rotulo = Label(janela,
font="Arial 10",
text='E-mail:',
bg="lightblue")
rotulo.place(x=25, y=70)
cxtexto1 = Entry(janela,
width=20,
font="Arial 12 bold")
cxtexto1.place(x=75, y=70)
email = cxtexto1.get()
rotulo = Label(janela,
font="Arial 10",
text='Senha:',
bg="lightblue")
rotulo.place(x=25, y=100)
cxtexto2 = Entry(janela,
width=20,
font="Arial 12 bold")
cxtexto2.place(x=75, y=100)
senha = cxtexto2.get()
bt2 = Button(janela,
width=10,
text="Salvar",
font="Arial 12 bold",
command=usuarios.cria_bd)
bt2.place(x=150, y=130)
janela.mainloop()
The code below shows the command to save inside the Sqlite
import sqlite3
def cria_bd(email, senha):
conn = sqlite3.connect('usuarios.db')
bd = conn.cursor()
bd.execute("""
CREATE TABLE IF NOT EXISTS Cadastro (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
Email TEXT NOT NULL,
Senha TEXT NOT NULL);""")
bd.execute("""
INSERT INTO Cadastro (Email, Senha)
VALUES (?,?)
""", (email, senha))
conn.commit()
conn.close()
return
Caro @Renato Cruz, thank you for your attention! Thank you very much!
– Wilson Junior