I'm studying, on my own, SQlite, I've already bought some courses, but I need some help.
Purpose: I would like to save the user-entered 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 on the save button, three columns (auto-increment id, email, password) must be saved in the database
The code below shows only the window code, Below is the code for the users module, where I put the SQLite code.
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 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