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

Question:

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.

Asked By: Nick

||

Answers:

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,)
Answered By: Christian W.

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()
Answered By: Jay
values = ('Select One',)
for i in symbols_from:
    values = values + (i,)

combo_symbol_name_from['values'] = values
combo_symbol_name_from.current(0)
Answered By: Funny Videos
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.