,否则我还建议将功能定义为DEF
我正在尝试从另一个函数访问函数中的条目。但是它告诉我它没有定义。我一直在研究很多,但我似乎找不到任何帮助我的东西。
这是我的代码,我一直在缩短它,以使你们更容易。虽然应该足以给您这个主意。
from tkinter import*
class hunterClass:
def BMHunter():
hunter = Tk()
hunter.title("Beast Mastery Gear Worth Calculator")
agiString = StringVar()
agiText = Label(hunter, text = "Input points of agility:").grid(row = 3, column = 0)
agiEntry = Entry(hunter, textvariable = agiString).grid(row = 3, column = 1)
calculate = Button(hunter, text = "Calculate", command = hunterClass.calculateFun).grid(row = 12, column = 1)
def calculateFun():
agiF = float(agiEntry.get())
window = Tk()
window.title("Gear Worth Calculator")
hunterText = Label(window, text = "Hunter").grid(row = 3, column = 0)
hunterBM = Button(window, text = "Beast Mastery", width = 12, command = hunterClass.BMHunter).grid(row = 4, column = 0)
您需要def BMHunter
中的另一个缩进来定义calculateFun
我假设您正在尝试使用Python中的封闭:
https://www.programiz.com/python-programming/closure
so
def BMHunter():
....
def calculateFun()
您的当前代码将calculateFun
作为同一类的另一个函数,而不是BMHunter
除非您故意使其静态/类方法
BMHunter(self)