PostGreSQL + tkinter conundrum

I am trying to create a program in tkinter which would implement PostGreSQL databases. All goes well until the issue of modifying data. The image below shows how it currently looks like
Bez tytułu
I wanted to make it so the modification process is composed of two subroutines: One takes the selected object and “moves it” to the inserts on left, so I can modify them, after pressing the button the object gets modified and all is good. Here is mine “attempt”:

def MODIFY_USER():
    connect, cursor = connection_to_db()
    i = listbox_object_list.index(ACTIVE)
    entry_name_unit.delete(0, END)
    entry_adress_unit.delete(0, END)
    entry_phone_number_u.delete(0, END)


    # Fetch user data from PostgreSQL
    cursor.execute('SELECT * FROM units WHERE "ID_UNIT" = %s', (i + 1,))
    user_data = cursor.fetchone()

    entry_name_unit.insert(0, user_data[1])
    entry_adress_unit.insert(0, user_data[2])
    entry_phone_number_u.insert(0, user_data[3])


    button_add_object.config(text="Save", command=lambda: UPDATE_USER(i))

def UPDATE_USER(i: int):
    connect, cursor = connection_to_db()
    i = listbox_object_list.index(ACTIVE)
    cursor.execute("UPDATE units SET name = %s, adress = %s, phonenumber = %s WHERE 'ID_UNIT' = %s",
                   (entry_name_unit.get(), entry_surname.get(), entry_phone_number_u.get(), i + 1))
    connect.commit()

    button_add_object.config(text="Add object", command=ADD_UNIT)
    entry_name_unit.delete(0, END)
    entry_adress_unit.delete(0, END)
    entry_phone_number_u.delete(0, END)

Which itself is an attempt of morphing this to use PostGreSQL:

def MODIFY_USER():
    i = listbox_object_list.index(ACTIVE)
    entry_name.delete(0, END)
    entry_surname.delete(0, END)
    entry_city.delete(0, END)
    entry_posts.delete(0, END)
    entry_name.insert(0, Users[i].name)
    entry_surname.insert(0, Users[i].surname)
    entry_city.insert(0, Users[i].location)
    entry_posts.insert(0, Users[i].posts)
    button_add_object.config(text="Zapisz zmiany", command=lambda:UPDATE_USER(i))

def UPDATE_USER(i:int):
    i = listbox_object_list.index(ACTIVE)
    Users[i].name = entry_name.get()
    Users[i].surname= entry_surname.get()
    Users[i].location= entry_city.get()
    Users[i].posts = entry_posts.get()
    button_add_object.config(text="Add object", command=ADD_USER)
    entry_name.delete(0, END)
    entry_surname.delete(0, END)
    entry_city.delete(0, END)
    entry_posts.delete(0, END)
    USER_LIST()

The most common kind of error is this one:

 line 200, in MODIFY_USER
    entry_name_unit.insert(0, user_data[1])
                              ~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

What should I do? Scrap the code in its entirety and start anew? 

Here’s an example using the Treeview widget to make a listbox, which has the advantage that you refer to the rows by an ID instead of their current index:

import tkinter as tk
import tkinter.ttk as ttk

# The main window.
main_window = tk.Tk()
main_window.title('Example GUI')

# The frame to hold the list box.
list_frame = tk.Frame(main_window)
list_frame.pack(side='right')

# The list box with scroll bar.
yscrollbar = tk.Scrollbar(list_frame, orient='vertical')
yscrollbar.pack(side='right', fill='y')

listbox = ttk.Treeview(list_frame, show='headings', columns=['people'], yscrollcommand=yscrollbar.set)
listbox.pack(side='left', fill='both', expand=True)
listbox.heading('people', text='People')

yscrollbar.config(command=listbox.yview)

# When 1 row of the list box is selected, fill the entry boxes with the info.
def on_select_person(event=None):
    if len(listbox.selection()) == 1:
        # 1 row selected.
        person_id = listbox.selection()[0]
        person_info = people[person_id]
        name_var.set(person_info['name'])
        address_var.set(person_info['address'])
        phone_number_var.set(person_info['phone'])
    else:
        # 0 or >1 rows selected.
        name_var.set('')
        address_var.set('')
        phone_number_var.set('')

listbox.bind('<<TreeviewSelect>>', on_select_person)

# The frame to hold the entry boxes.
entry_frame = tk.Frame(main_window)
entry_frame.pack(side='bottom')

# The entry box for the name.
tk.Label(entry_frame, text='Name:').grid(row=0, column=0)

name_var = tk.StringVar()
name_entry = tk.Entry(entry_frame, textvariable=name_var)
name_entry.grid(row=0, column=1, sticky='we')

# The entry box for the address.
tk.Label(entry_frame, text='Address:').grid(row=1, column=0)

address_var = tk.StringVar()
address_entry = tk.Entry(entry_frame, textvariable=address_var)
address_entry.grid(row=1, column=1, sticky='we')

# The entry box for the phone number.
tk.Label(entry_frame, text='Phone number:').grid(row=2, column=0)

phone_number_var = tk.StringVar()
phone_number_entry = tk.Entry(entry_frame, textvariable=phone_number_var)
phone_number_entry.grid(row=2, column=1, sticky='we')

# The save button.
def on_save(event=None):
    if len(listbox.selection()) == 1:
        # Save the info.
        person_id = listbox.selection()[0]
        person_info = people[person_id]
        person_info['name'] = name_var.get()
        person_info['address'] = address_var.get()
        person_info['phone'] = phone_number_var.get()

        # Update the list box.
        listbox.item(person_id, values=(person_info['name'],))

save_button = tk.Button(entry_frame, text='Save info', command=on_save)
save_button.grid(row=4, column=0, columnspan=2)

# Create the people.
people = {}

for person_id in range(1, 21):
    people[str(person_id)] = {'name': f'Name {person_id}', 'address': f'Address {person_id}', 'phone': f'Phone {person_id}'}

# Fill the list box.
for person_id, person_info in people.items():
    listbox.insert('', 'end', values=(person_info['name'],), iid=person_id)

main_window.mainloop()
from tkinter import *
import psycopg2

root = Tk()
root.title('Postgres+Tk')
root.geometry("500x550")

def clear():
	f_name.delete(0, END)
	l_name.delete(0, END)
	
def query():
	# Configure and connect to Postgres
	conn = psycopg2.connect(
		host = '', 
		database ='' ,
		user = 'postgres' ,
		password  = '', 
		port = "5432",
		)
	c = conn.cursor()
	c.execute('''CREATE TABLE IF NOT EXISTS customers
		(first_name TEXT,
		last_name TEXT);
		''')
	conn.commit()
	conn.close()
	



def submit():
	# Configure and connect to Postgres
	conn = psycopg2.connect(
		host = 'localhost', 
		database ='company' ,
		user = 'postgres' ,
		password  = '', 
		port = "5432",
		)
	# Create a cursor
	c = conn.cursor()
	# Insert data into table
	thing1 = f_name.get()
	thing2 = l_name.get()
	c.execute('''INSERT INTO customers (first_name, last_name)
		VALUES (%s, %s)''', (thing1, thing2)
		)
	conn.commit()	
	conn.close()
		
	update()
	clear()
	



def update():
	# Configure and connect to Postgres
	conn = psycopg2.connect(
		host = 'localhost', 
		database ='company' ,
		user = 'postgres' ,
		password  = '', 
		port = "5432",
		)

	# Create a cursor
	c = conn.cursor()

	# Grab stuff from online database
	c.execute("SELECT * FROM customers")
	records = c.fetchall()

	output = ''

	# Loop thru the results
	for record in records:
		output_label.config(text=f'{output}\n{record[0]} {record[1]}')
		output = output_label['text']

	conn.close()
	


# Create The GUI For The App
my_frame = LabelFrame(root, text="Postgres Example")
my_frame.pack(pady=20)

f_label = Label(my_frame, text="First Name:")
f_label.grid(row=0, column=0, pady=10, padx=10)

f_name = Entry(my_frame, font=("Helvetica, 18"))
f_name.grid(row=0, column=1, pady=10, padx=10)

l_label = Label(my_frame, text="Last Name:")
l_label.grid(row=1, column=0, pady=10, padx=10)

l_name = Entry(my_frame, font=("Helvetica, 18"))
l_name.grid(row=1, column=1, pady=10, padx=10)

submit_button = Button(my_frame, text="Submit", command=submit)
submit_button.grid(row=2, column=0, pady=10, padx=10)

update_button = Button(my_frame, text="Update", command=update)
update_button.grid(row=2, column=1, pady=10, padx=10)

output_label = Label(root, text="")
output_label.pack(pady=50)



query()

root.mainloop()