'How to display a row from a database that selected by the user

The program will ask the user to insert an ID in my code. If the ID is found in the database, it will take them to Administrator_Settings(), where they would be given the option to edit, remove, and view the profile connected to that ID. However, In the image provided, I would like to have a table displaying the First and the last name of the profile that the user selected. This is done to verify that the designated account is correct.

I plan to display information that only belongs to the ID that the user selected in different windows, so any tips on only showing information from the desired profile will be great!

Picture Reference

Here is what I tried so far:

def search_id():
        import sqlite3
        import tkinter
        # grabbing the inputting id
        lookup_record = United.get()
        conn = sqlite3.connect('MEMBERinformation.db')
        cur = conn.cursor()
        # grabs all the ids from the table
        cur.execute('SELECT MemberID FROM ChurchMemberInformation')
        for row in cur:
            # slicing the retrieved row so it is just the id (no symbols in it)
            row = str(row)[2:9]
            # checking to see if the current row retrieved is equal to the inputted id
            if (str(lookup_record) == row):
                self.Administrator_Settings()
                # go to next page by calling the function associated with it (note how I did it below.
                return
        # if the record does not exist it will end up here
        answer = tkinter.messagebox.askyesno('Not Found',
                                             "This Member is not found. Click 'yes' if you would like to proceed"
                                             " to the directory  and find someone there manually, or click 'no' if "
                                             " you wish to retry again.")
        if answer:
            self.Directory()
            return
        # if answer is no, it will return to the page
        else:
            return
    
def connect():
        conn = sqlite3.connect("MEMBERinformation.db")
        cur = conn.cursor()
        cur.execute(
            "CREATE TABLE IF NOT EXISTS ChurchMemberInformation(MemberID TEXT PRIMARY KEY, "
            "FirstName TEXT, LastName TEXT, Address TEXT, PhoneNumber)")
        conn.commit()
        conn.close()

    # Frame
    Table1 = Frame(self.ws)
    Table1.pack(anchor=CENTER, side=BOTTOM)
    Table1.place(relx=0.375, rely=0.45)

    # Connect the database
    connect()

    scrollBAR = Scrollbar(Table1)
    scrollBAR.pack(side=RIGHT, fill=Y)

    # Create Treeview widget
    global tree
    tree = ttk.Treeview(Table1, columns=("column1", "column2"), show='headings', yscrollcommand=scrollBAR.set)

    tree['columns'] = ('FIRST NAME', 'LAST NAME')
    tree.column('FIRST NAME', width=200, anchor=CENTER)
    tree.heading("#1", text="FIRST NAME")
    tree.column('LAST NAME', width=200, anchor=CENTER)
    tree.heading("#2", text="LAST NAME")
    tree.pack()

    conn = sqlite3.connect("MEMBERinformation.db")
    cur = conn.cursor()
    cur.execute("SELECT FirstName, LastName FROM ChurchMemberInformation")
    rows = cur.fetchall()
    for row in rows:
        print(United)  # print all records in the database
        tree.insert("", tk.END, values=row)

Thank you for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source