您面临的问题与您定义
OptionMenu
小装置。
事实上,它与tkinter选项菜单不同,因为您在声明中设置了默认值。因此,当您解压缩这些值时,第一个索引
"Gmail"
被视为
default
(此外,您不需要设置
dropdown_var
choices = ("Gmail", "Outlook/Hotmail", "Yahoo", "Comcast", "AT&T", "Verizon")
dropdown_var = StringVar()
def data(*args):
value = dropdown_var.get()
print value # no bracket for python2
l = ttk.Label(root, text="Select your e-mail provider : ")
l.pack(side="left")
# the 3rd parameter is the default value
option = ttk.OptionMenu(root, dropdown_var, choices[0], *choices)
option.pack(side="left", padx=10, pady=10)