0
他の関数内の関数から変数を呼び出す際に問題があります。私も電卓のユーザーは、いくつかの数字を入力することができる2つのエントリを持って関数が意図したとおりに機能しない、Python、TKinter
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)
:
def refineRate(event):
if refineRate(event) == int():
refine = int(refineRate(event))
return refine
else:
refine = float(refineRate(event))
return refine
と:
は、私は2つの機能を持っています。私は必要なもの
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
それはtry 'def f():f()'のように常に自分自身を呼び出す再帰関数です。関数を呼び出すたびに 'if'条件をチェックし、再度呼び出すため、elseブロックに到達しません。 ..無限に(まあ、Pythonのエラーが出るまで)。実際、あなたはいつも再帰呼び出しを使用して終了します。だから私は、あなたが何を期待しているのか、あなたの機能が何をするのかを知らない。 –