Connesione interfaccia Py con DB Postgresql

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


root = customtkinter.CTk()

def login():

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:


Think about your problem in two completely different halves. You can tackle them in either order.

  1. Make a user interface with “Username”, “Password”, etc, and when the user clicks “Login”, get all the important pieces of information in variables, and then print them out. (You’re almost there already, just a last couple of steps to go.)
  2. Completely separately, make a function that does the database work. Give it parameters for the username, password, etc. Test this function by hard-coding a call to it; you don’t need a user interface at all. Something like:
log_in("test-user", "secret-password-who-dis", True)

Once you have both halves working, it should be quite easy to put them together, especially if you’ve used good variable names.

Actually I had already done so, the two halves already work, the only problem is in the button that once pressed should send the name and pass to db but I can not attribute this function