python - Global variables aren't working -
my global variables not working in code. i'm new , can't seem figure out: have set variables (only showing gna this), can manipulated entry field, triggered corresponding button. reason, it's not taking changes within loop. i'm trying make changed variable can graphed well, gives me following error:
exception in tkinter callback traceback (most recent call last): file "c:\program files\python35\lib\tkinter\__init__.py", line 1549, in __call__ return self.func(*args) file "g:/python/eulers.py", line 64, in graph v[i + 1] = 1 / c * (gna * f[i] - gk * u[i]) * del_t + v[i] typeerror: ufunc 'multiply' did not contain loop signature matching types dtype('< u32') dtype('< u32') dtype('< u32')
here code:
gna = 0.9 gnalabel = label(topframe, text="gna = %s" % gna) gnalabel.pack() gnaentry = entry(topframe, justify=center) gnaentry.pack() def gnacallback(): global gna gna = gnaentry.get() gnalabel.config(text="c = %s" % gna) gnabutton = button(topframe, text="change", width=10, command=gnacallback) gnabutton.pack() def graph(): global c, gna, gk, beta, gamma in range(0, len(t)-1): stinum = np.floor(i / 3000) stimt = 3000 + 3000 * (stinum - 1) f[i] = v[i] * (1 - (((v[i]) ** 2) / 3)) v[i + 1] = 1 / c * (gna * f[i] - gk * u[i]) * del_t + v[i] if(i == stimt): v[i + 1] = v[i + 1] + v_stim u[i + 1] = (v[i] + beta - gamma * u[i]) * del_t + u[i] plt.plot(v) plt.show()
gna = gnaentry.get()
entry.get
returns string, unsuitable type arithmetic you're doing in graph
. try converting number first.
gna = float(gnaentry.get()) #or perhaps `int` if it's integer
Comments
Post a Comment