Tkinter optionmenu功能

时间:2017-08-30 00:44:27

标签: python function tkinter optionmenu

使用Tkinter模块,我尝试根据选项菜单的某些选择引出操作,如果选项菜单不在指定选项上,则取消该操作。问题是程序将编译,除非两个选项菜单="高音谱号"它有点停止工作。我尝试使用if语句,除了我不确定如何摆脱它调用的标签之外,它的工作正常。

originalKey = Label(window, text = "Original Key Signature", bg = 'black', fg = 'white')
originalKey.pack()

oKey = StringVar(window)
oKey.set("Select") # initial value
optionold = OptionMenu(window, oKey, "treble clef", "bass clef", "alto clef")
optionold.config(bg = 'black', fg = 'white')
optionold.pack()

#new key selections option menu
def displayKey(str):
while nKey.get() == "treble clef" and oKey.get() == "treble clef":
    testpic = Label(window, image = logoimage, bg = 'black')
    testpic.pack()
    break

newKey = Label(window, text = "New Key Signature", bg = 'black', fg = 'white')
newKey.pack()

nKey = StringVar(window)
nKey.set("select") # initial value
optionnew = OptionMenu(window, nKey, "treble clef", "bass clef", "alto clef",             
command = displayKey)
optionnew.config(bg = 'black', fg = 'white')
optionnew.pack()

0 个答案:

没有答案