Nick
Nick

Reputation: 33

Appending values to TTK Combobox['values'] without reloading combobox

I need to add values to a ttk.combobox without reloading the whole thing. The current selection on the GUI should not be reloaded when values are added to it.

I need something like this:

for string in listofstrings:
    if string not in self.combobox1['values']:
        self.combobox1['values'].append(string)

When I try it like this, I get this error:

AttributeError: 'tuple' object has no attribute 'append'

(as expected).

Thanks in advance for the help.

Upvotes: 3

Views: 13636

Answers (3)

Funny Videos
Funny Videos

Reputation: 1

values = ('Select One',)
for i in symbols_from:
    values = values + (i,)

combo_symbol_name_from['values'] = values
combo_symbol_name_from.current(0)

Upvotes: 0

Jay
Jay

Reputation: 21

I ran into this post while looking for a way to append items to a Combobox. I am loading values from a spreadsheet. I created a list and then added items in a loop. After the loop is over, all the values are assigned to a Combobox. I hope this helps someone.

Combobox1.delete(0, END)
wb = load_workbook("types.xlsx")
ws = wb.active
r = 1
string=['']

for row in ws.iter_rows(min_row=1, min_col=1):
    val=str(ws.cell(row=r, column=1).value)
    string.append(val)
    r = r + 1

Combobox1['values'] = string
wb.close()

Upvotes: 1

Christian W.
Christian W.

Reputation: 2660

How about:

if string not in self.combobox1['values']:
    self.combobox1['values'] = (*self.combobox1['values'], string)

Or alternatively:

if string not in self.combobox1['values']:
    self.combobox1['values'] += (string,)

Upvotes: 10

Related Questions