我正在尝试从另一个函数访问函数内的条目。但它告诉我它没有定义。我一直在研究很多,但我似乎无法找到任何可以帮助我的东西。
这是我的代码,我一直在缩短它以便让你们更轻松。虽然它应该足以让你有这个想法。
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)
答案 0 :(得分:0)
您需要def BMHunter
中的其他缩进来定义calculateFun
我假设您正在尝试在python中使用闭包:
https://www.programiz.com/python-programming/closure
所以
def BMHunter():
....
def calculateFun()
您当前的代码将calculateFun
作为同一类的另一个函数而不是BMHunter
中的本地函数
我还建议将函数定义为def BMHunter(self)
,除非你故意想让它成为静态/类方法