在Tkinter中定义指数函数是有问题的。我的吉他是由三个组合框组成的,我可以选择不同的数字。当我选择所有的数字时,它会显示一个基于指数函数的结果。我的意思是:
到目前为止,我得到的内容如下,但不起作用:
#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()非常感谢您提前!
发布于 2013-04-17 19:25:11
根据示例代码,没有任何地方将NumA、NumB或NumC设置为值,而且这些变量与任何小部件都没有关联。此外,您还创建了名为NumA、NumB和NumC的变量,但是在您的函数中使用的是Num_A、Num_B和Num_C。
https://stackoverflow.com/questions/16067204
复制相似问题