我是Python新手,遇到了以下问题。我已经创建了一个以材质为键,折射率为值的字典。在
用户从组合框中选择材质。同时,我想显示所选材料的折射率。但我做不到!
下面是我的密码。谢谢你的帮助。在from tkinter import *
from tkinter import ttk
def main():
materialDict = {'XO': 1.415, 'XO2': 1.424, 'Opt-EX': 1.431, 'TYRO-97': 1.44, 'AC-100': 1.415, 'Paragon': 1.442}
root = Tk()
root.geometry("1600x800+0+0")
root.title("TEST Form")
root.configure(bg='Dodgerblue4')
label_material = Label(root, text='Choose Material', bd=3, width=20, height=3).grid(row=0, column=1)
var_material = StringVar()
combo_material = ttk.Combobox(root, values=list(materialDict.keys()), justify=CENTER, textvariable=var_material)
combo_material.grid(row=0, column=2)
combo_material.current(0)
label_selected = Label(root, text="Here I want to print the value of the combobox selected item ")
label_selected.grid(row=1, column=3)
root.mainloop()
return
if __name__ == '__main__':
main()