Python中的可编辑组合框

时间:2018-08-24 04:11:59

标签: python tkinter drop-down-menu combobox ttk

如何将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()

1 个答案:

答案 0 :(得分:1)

每当要将项目添加到列表中时,都需要重新配置组合框。

示例:

def clickMe():
    List.append(name.get())
    numberChosen.configure(values=List)