我在尝试在 Tkinter gui 中定义指数函数时遇到问题。我的 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()
非常感谢您!
请您参考如下方法:
根据您的示例代码,您没有在任何地方将 NumA、NumB 或 NumC 设置为一个值,并且这些变量不是与任何小部件相关联。另外,您创建了名为 NumA、NumB 和 NumC 的变量,但在您的函数中您使用的是 Num_A, Num_B 和 Num_C。
