You are very close to making it all work, after I looked at myself, I could not find a single (not too complicated) way to determine the top Frame , so it would be best to just record the current position:
def __init__(self, parent, controller): ... self.position = 0
And to pass buttonBool to changePage , you can from here (Valve gives the best solution in my eyes, since lambda make expressions of the line of code are too long)
def __init__(self, parent, controller): ...
With these two (and implementing self.position in changePage ) you can accomplish what you initially set, all that is below this is the code browser in me.
Although using boolean will work, this strategy of working with extra arguments for callbacks allows you to pass any argument to changePage , so it will probably simplify the conventions of changePage if it receives the change on the pages (so that 1 or -1):
def go_next(event=None): self.changePage(1) next = ttk.Button(innerFrame, text = "Next", command = go_next) next.grid(row=2, sticky="E") def go_back(event=None): self.changePage(-1) back = ttk.Button(innerFrame, text = "Back", command = go_back) back.grid(row=2, sticky="W")
then changePage might look like this, although I'm not sure what will happen to self.position if you go to the wrong page:
def changePage(self,change): pages = [self.pageOne,self.pageTwo,self.pageThree] new_position = self.position + change if (new_postion < 0) or (new_postion <= len(pages)): show_frame(BlankPage)
Even better, if you keep a link to the next and back buttons, you can config them to indicate that this is the end / beginning:
def changePage(self,change): pages = [self.pageOne,self.pageTwo,self.pageThree] new_position = self.position + change if (0 <= new_postion < len(pages)): pages[new_position].tkraise() self.position = new_position else: show_frame(BlankPage) if new_position+1 >= len(pages): self.nextButton.config(text="End")
this way you will know when you reach your goal, even if there are no directions from the content. (or you can disable the buttons to prevent passage)