How to pass values from a group of object attributes into tkinter combobox values

I'm looking to populate a tkinter combobox with a list of attribute values contained within a set of objects from a certain class. I have a method that works but it seems inefficient as the number of objects rises.

I've attempted using while/for statements but am perhaps failing in syntax due to the formatting for tkinter values.

class Customer:
def __init__(self, name, people):
    self.name = name
    self.people = people

customer1 = Customer(“First Customer”, [“Brian”, “Sally”])
customer2 = Customer(“Second Customer”, [“Kevin”, “James”])
customer3 = Customer(“Third Customer”, [“Peter”, “Sarah”])

customer_list = [customer1, customer2, customer3]

from tkinter import *
from tkinter.ttk import *

window = Tk()
window.title(“Command Console”)
window.geometry(‘350x200’)

l1 = Label(window, text = “Select a customer.”)
l1.grid(column=0,row=0)

b1 = Button(window, text = “Grab”)
b1.grid(column=1,row=1)

c1 = Combobox(window)
c1[‘values’] = customer_list[0].name, customer_list[1].name,
customer_list[2].name
c1.grid(column=0,row=1)

Although the above works, it would be preferred to populate the .name values for i = 0 to i < len(customer_list) or similar, however I can’t work out a mechanism.

#python

2 Likes13.25 GEEK