Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将值添加到TTK组合框[';值';],而不重新加载组合框_Python_Python 3.x_Tkinter_Ttk - Fatal编程技术网

Python 将值添加到TTK组合框[';值';],而不重新加载组合框

Python 将值添加到TTK组合框[';值';],而不重新加载组合框,python,python-3.x,tkinter,ttk,Python,Python 3.x,Tkinter,Ttk,我需要在不重新加载整个内容的情况下向ttk.combobox添加值。添加值时,不应重新加载GUI上的当前选择 我需要这样的东西: for string in listofstrings: if string not in self.combobox1['values']: self.combobox1['values'].append(string) 当我像这样尝试时,会出现以下错误: AttributeError:“tuple”对象没有属性“append” (如预期的

我需要在不重新加载整个内容的情况下向ttk.combobox添加值。添加值时,不应重新加载GUI上的当前选择

我需要这样的东西:

for string in listofstrings:
    if string not in self.combobox1['values']:
        self.combobox1['values'].append(string)
当我像这样尝试时,会出现以下错误:

AttributeError:“tuple”对象没有属性“append”

(如预期的那样)

提前感谢您的帮助。

怎么样:

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

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

我在寻找将项目附加到组合框的方法时遇到了这篇文章。我正在从电子表格加载值。我创建了一个列表,然后在循环中添加了项目。循环结束后,所有值都分配给一个组合框。我希望这对某人有帮助

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()

他选择了第一个选项。工作起来很有魅力。谢谢第一个选项是“重新加载整个东西”