Hello,
my code has the function of creating an interface where you enter data and once pressed the button, the data is sent to the postresql database, but I can not make the link of the button with the db…
Someone can help me?
import customtkinter
import psycopg2
import psycopg2.extras
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
root = customtkinter.CTk()
root.geometry("500x350")
def login():
print("Test")
frame = customtkinter.CTkFrame(master=root)
frame.pack(pady=20, padx=60, fill="both", expand=True)
label = customtkinter.CTkLabel(master=frame, text="Login System", text_font=("Roboto", 24))
label.pack(pady=12, padx= 10)
entry1= customtkinter.CTkEntry(master=frame, placeholder_text="Username")
entry1.pack(pady=12 , padx=10)
entry2= customtkinter.CTkEntry(master=frame, placeholder_text="Password", show="*")
entry2.pack(pady=12, padx=10)
button= customtkinter.CTkButton(master=frame, text="Login", command= login)
button.pack(pady=12, padx=10)
checkbox = customtkinter.CTkCheckBox(master=frame, text="Remember Me")
checkbox.pack(pady=12, padx=10)
connection = psycopg2.connect(
host = "localhost",
database = "db1",
user = "postgres",
password = "123456",
)
print("connection successful")
with connection.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
cur.execute('DROP TABLE IF EXISTS two')
cur = connection.cursor()
cur.execute("CREATE TABLE two(name TEXT, age INT, height REAL)")
#cur.execute("INSERT INTO two(name, age, height) VALUES(%s,%s,%s)", ("Aba", 20, 178))
cur.execute("SELECT * FROM two")
rows = cur.fetchall()
for r in rows:
print(rows)
cur.close()
connection.commit()
connection.close()
root.mainloop()