但是我显示了这个框架,但是只有当这个框架实际显示(而不是程序运行时)时,我才需要最后一行运行。事情在功能启动时,该框架显示当显示框架时运行超级 - Python Tkinter
class FrameTwo(reviseTen):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.instructions = tk.Label(self, text="Click on the option you think is correct, then click 'Proceed to next question'")
self.startButton = tk.Button(self, text="Click here to start revision session")
self.optionOne = tk.Button(self, text="Option One", command=super(FrameTwo, self).clickOptionOne)
self.optionTwo = tk.Button(self, text="Option Two", command=super(FrameTwo, self).clickOptionTwo)
self.optionThree = tk.Button(self, text="Option Three", command=super(FrameTwo, self).clickOptionThree)
self.optionFour = tk.Button(self, text="Option Four", command=super(FrameTwo, self).clickOptionFour)
self.question = tk.Label(self, text="What is the definition of: ")
self.proceedButton = tk.Button(self, text="Proceed to next question", command=lambda: controller.show_frame(FrameThree))
############# EDIT ####################
self.bind("<<Show>>", self.do_something)
def do_something(self, event):
self.start()
编辑在这里,我只希望发生的情况是我show_frame方法:
def show_frame(self, cont): # Method to show the current frame being used
for frame in self.frames.values():
frame.grid_remove()
frame = self.frames[cont]
frame.tkraise()
frame.update()
frame.grid()
frame.event_generate("<<Show>>")
'class FrameTwo(reviseTen)' - 什么是'reviseTen',为什么'FrameTwo'从它继承?你为什么要调用'tk.Frame .__ init__'而不是'reviseTen .__ init__'或'super().__ init__'? – user2357112
请不要破坏你的帖子。一旦你发布了一个问题,它就一般属于Stack Overflow社区(根据[CC-by-SA许可证](https://creativecommons.org/licenses/by-sa/3.0/))。如果您想要从您的帐户中取消关联此信息,请参阅[解除请求的正确途径是什么?](https://meta.stackoverflow.com/q/323395/5244995)。 –