Question

I am having a problem trying to define a exponential function in a Tkinter gui. My Gui is composed by three combo boxes where I can choose different numbers. When I select all numbers it displays a result based on a exponential function. What I mean is as follows:

  • Select NumberA #Combobox 1
  • Select NumberB #Combobox 2
  • Select NumberC #Combobox 3

    Result = exp[(-NumberA/NumberB)* NumberC]
    

What I have so far is as follows, but it doesn't work:

#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()

Thank you very much in advance!

Was it helpful?

Solution

Based on your example code, nowhere do you set NumA, NumB, or NumC to a value, and those variables aren't associated with any widgets. Plus, you create variables named NumA, NumB and NumC, but in your function you're using Num_A, Num_B and Num_C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top