0
我无法从另一个函数内的函数调用变量。功能不按预期工作,蟒蛇,TKinter
我有两个功能:
def refineRate(event):
if refineRate(event) == int():
refine = int(refineRate(event))
return refine
else:
refine = float(refineRate(event))
return refine
和:
def veldCalc(event):
minValue = open("mineral_value.csv", "r")
veld = minValue.readlines()[0]
minValue.close()
veld = veld[0:3]
veld = int(veld)
veld = veld/100 * refineRate(event)
refinedVeld = veld * int(veldCalc)
print (refinedVeld)
我也有两个条目,其中计算器的用户可以输入一些数字。
repro = Label(root, text="Reprocessing %")
repro_entry = Entry(root)
repro.grid(row=0, column=0)
repro_entry.grid(row=0, column=1)
veld = Label(root, text="Veldspar: ")
veld_entry = Entry(root)
veld.grid(row=1, column=0)
veld_entry.grid(row=1, column=1)
repro_entry.bind("<KeyPress>", refineRate)
veld_entry.bind("<KeyPress>", veldCalc)
我需要的是为用户的输入有refineRate
,哪些应该再打通函数传递和存储供以后使用。在当他们进入他们拥有量,veldCalc
功能,那么应该拉动用户从以前的功能改进率和做数学题,但即时得到以下错误
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Ganjena\AppData\Local\Programs\Python\Python36-32\lib\tkinter\__init__.py", line 1699, in __call__
return self.func(*args)
File "C:/Users/Ganjena/Desktop/Course/Projects/helloworld/ORE FUNCTIONS/Ore Calculator.py", line 5, in refineRate
if refineRate(event) == int():
File "C:/Users/Ganjena/Desktop/Course/Projects/helloworld/ORE FUNCTIONS/Ore Calculator.py", line 5, in refineRate
if refineRate(event) == int():
File "C:/Users/Ganjena/Desktop/Course/Projects/helloworld/ORE FUNCTIONS/Ore Calculator.py", line 5, in refineRate
if refineRate(event) == int():
[Previous line repeated 990 more times]
RecursionError: maximum recursion depth exceede
任何想法,这是为什么不工作?先谢谢你。
在你的第一个功能将永远不会停止递归,你总是有你'if'条件的递归调用... –
确定我想我明白了,我怎么能停止?但它不是一个循环,为什么它会继续运行? – Gromit
因为它是一个总是自己调用的递归函数,就像尝试'def f():f()'你永远不会到达你的else块,因为每次调用函数时,它都会检查if条件并再次调用自己。无尽的(好吧,直到Python出错)。事实上,你总是最终使用递归调用...所以我不知道你期望发生什么或者你的函数是怎么做的。 –