所以我正在研究课外学习,学习python并回顾我在学校学到的主题,如rsa,fib和其他与数学相关的主题。
我正在尝试使用通用的clearOptFrame(self,frame),可以在任何帧运行时调用以重置回主Option框架(所以从RSA框架转到主菜单,clearOptFrame(rsaFrame)会被调用,用户将返回主菜单)
但由于某种原因,我的代码无法识别我传递给它的参数(帧)。 这是我的代码:
#middle of calling function
global backButton
backButton = Button(optimizeFrame, text="Back", command = clearOptionFrame(optimizeFrame))
backButton.pack()
goButton2.pack()
#Clears the frame and inits main menu
def clearOptionFrame(self, frame):
frame.pack_forget()
initOptionFrame()
当我运行此代码时,我得到错误声称clearOptionFrame()不接受参数:
File "mathGUI.py", line 26, in optInit
backButton = Button(optimizeFrame, text="Back", command = clearOptionFrame(optimizeFrame))
TypeError: clearOptionFrame() takes no arguments (1 given)
为什么会这样?