【发布时间】:2013-03-18 22:12:52
【问题描述】:
我正在创建一个 GUI,变量正在发生变化。
它从计算一个值 theta 开始,当我单击一个按钮时,它被传递到一个 Entry 字段(这写在一个函数中:thetaVar.set(CalcTheta(grensVar.get(), data[:,1], data[:,2])))。
thetaVar = IntVar()
def callbackTheta(name, index, mode):
thetaValue = nGui.globalgetvar(name)
nGui.globalsetvar(name, thetaValue)
wtheta = thetaVar.trace_variable('w', callbackTheta)
rtheta = thetaVar.trace_variable('r', callbackTheta)
entryTheta = Entry(textvariable=thetaVar).place(x=90, y=202)
这行得通(并且我在 Entry 字段中看到了该值),但是当我稍后尝试获取此值时,它不起作用。 我相信我什么都试过了:
thetaVar.get() # with print, returns the integer 0, this is the initial value
# that is displayed, even though at that moment it shows 0.4341.
thetaVar # with print, returns 'PY_VAR3'
thetaValue # with print, global value not defined
entryTheta.get() # AttributeError: 'NoneType' object has no attribute 'get'
rtheta # print returns: 37430496callbackTheta
我不明白这个值存储在哪里以及如何在另一个函数中使用该条目的值。即使我在实际的 .set 之后尝试其中任何一个,我似乎也无法在之后打印条目的这个特定值。
在 Windows 8 上使用 tkinter 和 Python 3.3。
【问题讨论】:
-
我列出了我尝试过的东西。请看第二段代码。