PythonTkinter 练习7之OptionMenu 选项菜单
#Time: 2020/02/29
#Author: Xiaohong
#运行环境: OS: Win7 64位 专业版Pack1
# Python: 3.7
功能:创建OptionMenu 选项菜单,并获取当前值
from tkinter import *
main=Tk()
v1=StringVar(main)
options=['File','Edit','View','Tools','Window','Help']
v1.set(options[0])
om=OptionMenu(main,v1,*options)
om.pack()
text1=Text(main,width=30,height=15)
text1.pack()
def getoption():
print(v1.get())
text1.insert(INSERT,'你当前选择在是:'+v1.get()+'\n')
button1=Button(main,text='获取OptionMenu的当前值',command=getoption)
button1.pack()
mainloop()
运行效果是: