我在尝试在 Tkinter gui 中定义指数函数时遇到问题。My Gui 由三个组合框组成,我可以在其中选择不同的数字。当我选择所有数字时,它会显示基于指数函数的结果。我的意思如下:
- 选择 NumberA #Combobox 1
- 选择 NumberB #Combobox 2
选择 NumberC #Combobox 3
Result = exp[(-NumberA/NumberB)* NumberC]
到目前为止我所拥有的如下,但它不起作用:
#Main Selection
def exponential(*args):
try:
product.set('%g' %math.exp((float(Num_A.get())/float(Num_B.get())*float(Num_C.get()),2)))
except ValueError:
pass
## variables
NumA = StringVar()
NumB = StringVar()
NumC = StringVar()
product= DoubleVar()
#Combo boxes,
#NumA NumB and NumC are similar
ttk.Label(stepTen, text="Select A):").grid(column =3, row = 0)
NumA_Select = Combobox(stepTen, values=("0.1", "0.2", "0.3","0.4",),textvariable=Num_OneT)
NumA_Select.grid(column=4, row=0, columnspan="5", sticky="nswe")
NumA.trace("w",exponential)
## display results
ttk.Label(stepTen, text = "Exponential Dist result:").grid(column = 3, row = 12)
ttk.Label(stepTen, textvariable=product).grid(column = 4, row = 12)
#End Code
root.mainloop()
非常感谢您!