python - 如何清除 tkinter 组合框?
问题描述
我在 tkinter 中使用了多个组合框,我已将值列表传递给每个框。
目前,在您选择一个选项后,您无法清除该框,一些选择仍然存在
如果您想取消选择一个框,我希望能够清除所有框或具有“空白”值。
到目前为止,我已经尝试分配一个单独的按钮来清除整个选择,但我得到了错误。该按钮分配有以下命令:
for c in categories:
ttk.Label(text=c, relief=tk.RIDGE, width=15).grid(row=r,column=0)
categoriesParts = ttk.Combobox(root, textvariable = listVariables[r], values=listMakers[r],width=10, state="readonly")
categoriesParts.grid(row=r,column=1)
r = r + 1
def clearComboBox():
categoriesParts.delete(0, END)
browseButton_Clear = tk.Button(text='Clear Config', command=clearComboBox, bg='green', fg='white')
我收到错误消息: AttributeError: module 'tkinter.ttk' has no attribute 'tk'
编辑:工作代码,如果有人需要:
list_of_widgets = []
for c in categories:
ttk.Label(text=c, relief=tk.RIDGE, width=15).grid(row=r,column=0)
categoriesParts = ttk.Combobox(root, textvariable = listVariables[r], values=listMakers[r], width=10, state="readonly")
categoriesParts.grid(row=r,column=1)
list_of_widgets.append(categoriesParts)
r = r + 1
def clearComboBox():
for widget in list_of_widgets:
widget.set('')
browseButton_Clear = tk.Button(text='Clear Config', command=clearComboBox, bg='green', fg='white')
解决方案
推荐阅读
- android - java.lang.IllegalStateException:找不到函数 androidx.compose.internal.restartableFunctionInstance
- reactjs - 到达路由器的问题嵌套路由
- r - 用户提示中断循环 - 如何自动响应?
- python-sphinx - 从 html、sphinx 中删除上一个和下一个主题
- google-apps-script - 为什么我的拆分列出现语法错误?
- powerbi - 记录排除措施在 Matrix Visual 中不起作用
- python - 无法通过 boto3 创建 S3 批处理作业 - 请求无效
- c# - 如何获得具有多个可能字符的字符串的 IndexOf?
- docker - 在 Google Cloud Build 中构建 Docker 映像时如何保留 cmake 更改?
- java - Docker Compose 中 Keycloak 的 Spring Boot 问题