Python 中的可编辑组合框
Editable Combobox in Python
如何将 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)
如何将 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)