Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 3.x 如何在gui python中打印给定字典值中的数字?_Python 3.x_User Interface_Tkinter_Dropdown - Fatal编程技术网

Python 3.x 如何在gui python中打印给定字典值中的数字?

Python 3.x 如何在gui python中打印给定字典值中的数字?,python-3.x,user-interface,tkinter,dropdown,Python 3.x,User Interface,Tkinter,Dropdown,通过修改代码来帮助我 示例代码: values={"High School":"1","Intermediate":"2","Under Graduate":"3","Graduate":"4","Post Graduate":"5"} c=StringVar() droplist=OptionMenu(w,c, *values) droplist.config(width=28) c.set('Qualification') droplist.place(x=260,y=175) e1=En

通过修改代码来帮助我

示例代码:

values={"High School":"1","Intermediate":"2","Under Graduate":"3","Graduate":"4","Post Graduate":"5"}
c=StringVar()
droplist=OptionMenu(w,c, *values)
droplist.config(width=28)
c.set('Qualification') 
droplist.place(x=260,y=175)
e1=Entry(w,font=( 20 ),bd=2,width=28,textvariable=exp)
e1.place(x=250,y=215)
def a():
    print(c.get())
button1 = Button(w, text="Print",command=lambda: a())
button1.place(x=300,y=235)
预期输出: 1. 显示的输出:
高中

如果我理解正确,您希望在GUI中打印选项中选择的值。您可以按如下方式添加输出标签

def a():
    print(c.get())
    value = c.get()
    Label(text="Displayed output: ").place(x=260, y = 300)
    new_text = Label(text=value).place(x=400, y=300)
在您的示例代码中,您将选择该选项,您可以将其传递给Label小部件,Label小部件是用于显示文本的标准Tkinter小部件

输出


参考资料:

我不太清楚你在问什么。您希望输出精确到哪里?我看到一个
按钮
和一个
选项菜单
和一个
打印
你想用哪一个?什么决定了什么输出到它应该去的地方?当我点击
按钮时,它应该
打印
1
2
这样的值,根据我们在
下拉列表中的选择,它应该在
选项菜单中选择一个选项
打印
在第一行代码中指定给它们的相邻值。