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
这样的值,根据我们在下拉列表中的选择,它应该在选项菜单中选择一个选项打印
在第一行代码中指定给它们的相邻值。