如何将List
设置为Combobox
numberChosen
的值?在此之后,我想用我的条目编辑List
。我需要一个循环吗?
如果有人能帮助我,太好了,谢谢!
import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext
# window
win = tk.Tk()
win.title("menu")
# button click event
def clickMe():
action.configure(command='List = [nameEntered]')
# text box entry
ttk.Label(win, text="Eingabe:").grid(column=0, row=0)
name = tk.StringVar()
nameEntered = ttk.Entry(win, width=12, textvariable=name)
nameEntered.grid(column=0, row=1)
# button
action = ttk.Button(win, text="Enter", command=clickMe)
action.grid(column=2, row=1)
List = [nameEntered]
# drop down menu
ttk.Label(win, text="Auswahl:").grid(column=1, row=0)
number = tk.StringVar()
numberChosen = ttk.Combobox(win, width=12)
numberChosen['values'] = List
numberChosen.grid(column=1, row=1)
win.mainloop()
最佳答案
每当您要将项目添加到列表中时,都需要重新配置组合框。
例:
def clickMe():
List.append(name.get())
numberChosen.configure(values=List)
关于python - Python中的可编辑组合框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51997365/