1
我有以下代碼,需要它用新值更新同一個下拉列表。目前它只是在現有的權利中創建一個新的清單。有關如何實現這一目標的任何建議?更新選項菜單問題
import os
import sys
import Tkinter as tk
def edit():
var.set('Choose build')
choices =['one','two','three','four','five','six','seven','eight','nine','ten']
option = tk.OptionMenu(root, var, *choices)
option.pack(side='left', padx=10, pady=20)
root.mainloop()
root = tk.Tk()
var = tk.StringVar(root)
var.set('Choose build')
option = tk.OptionMenu(root, var, '')
root.geometry("%dx%d+%d+%d" % (500, 150, 200, 150))
root.title("QCT Multimedia Build Metrics")
button = tk.Button(root, text="Edit Config", command=edit)
button.pack(side='left', padx=20, pady=10)
choices = ['one','two','three','four','five']
option = tk.OptionMenu(root, var, *choices)
option.pack(side='left', padx=10, pady=20)
root.mainloop()
什麼是無功?修正你的格式。 –