我正在制作一个音乐旋律生成器,它会根据所选的琴键为您提供随机音符,并且正在tkinter中制作一个GUI。有一个下拉列表可以选择到目前为止我添加的键,当您单击“确定”时,我希望它在标签中显示该键,但是显示“ PY_VARO”。我该怎么办,它显示选定的密钥?
import random
from tkinter import *
notes = []
keys = [
"c major",
"d major",
"e major",
"f major",
"g major",
"a major",
"b major"]
master = Tk()
pickedkey = StringVar(master)
pickedkey.set(keys[0])
opmen = OptionMenu(master, pickedkey, *keys)
opmen.pack()
def pick():
print(pickedkey.get())
lbl.config(text= pickedkey)
lbl = Label(master, text ="")
b = Button(master, text="Okay", command = pick)
b.pack()
lbl.pack()
mainloop()