0
我正试图从python中使用Tkinter的用户输入计算公式。代码如下:将用户值存储在输入框中以计算Tkinter中的值
import math
from tkinter import *
def Solar_Param():
d = Interface.get()
S_E = 1367*(1 + 0.0334 * math.cos(((math.pi*360)/180) * (d - 2.7206)/365.25))
nlabel1 = Label(nGui, text = S_E).pack(side="left")
return S_E
nGui = Tk()
Interface = IntVar()
nGui.title("Solar Calculations")
nlabel = Label(text = "User Interface for Solar Calculation")
nlabel.pack()
nbutton = Button(nGui, text = "Calculate", command = Solar_Param).pack()
nEntry = Entry(nGui, textvariable = Interface).pack()
nGui.mainloop()
这里,S_E的值是使用默认值d自动计算的,即0,我不想要。即使我将输入更改为UI中的某个其他值,输出仍然会计算为默认值。
我试过使用自我方法,但我的上级不希望代码变得复杂。我应该如何计算S_E的值而不用更改源代码?
首先请阅读:http://stackoverflow.com/questions/21592630/why-do-my-tkinter-widgets- get-stored-as-none –
@EricLevieil:虽然这是很好的建议,但它与问题中的问题无关。 –