Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何用参数填充tkinter中的OptionMenu?_Python_Dictionary_Tkinter - Fatal编程技术网

Python 如何用参数填充tkinter中的OptionMenu?

Python 如何用参数填充tkinter中的OptionMenu?,python,dictionary,tkinter,Python,Dictionary,Tkinter,目前,我已经使用tkinter制作了一个下拉菜单的基本模板,它有三个参数1、2、3 from tkinter import * master = Tk() variable = StringVar() variable.set("one") # default value w = OptionMenu(master, variable, "one", "two", "three") w.pack() mainloop() 请参见上图以获得更清晰的信息 现在我有了30个键值对的字典,如

目前,我已经使用tkinter制作了一个下拉菜单的基本模板,它有三个参数1、2、3

from tkinter import *

master = Tk()

variable = StringVar()
variable.set("one") # default value

w = OptionMenu(master, variable, "one", "two", "three")
w.pack()

mainloop()

请参见上图以获得更清晰的信息

现在我有了30个键值对的字典,如何在OptionMenu中将它们作为选项填充。 字典:

"Belgium (Dutch)": "nl_be",
                 "Hungary": "hu_hu",
                 "Chile": "es_cl",
                 "Belgium (French)": "fr_be",
                 "Mexico": "es_mx",
                 "Hong Kong": "hk",
                 "Turkey": "tr_tr",
                 "Ireland": "en_ie",
                 "Ghana": "en_gh",
                 "Argentina": "es_ar",
                 "Slovakia": "sk_sk",
我只想要字典的键作为选项菜单中的选项。
在OptionMenu()中传递字典的每个键不是他们的任何智能技术。

您可以使用
*
将列表解压为许多参数

OptionMenu(master, variable, *data.keys())
满满的


您可以使用
*
将列表解压为多个参数

OptionMenu(master, variable, *data.keys())
满满的