Update frame on tab switch in ttk.Notebook Update frame on tab switch in ttk.Notebook tkinter tkinter

Update frame on tab switch in ttk.Notebook


You can bind to the <Visibility> or <Map> event of the frame. For example:

class MyFrame(ttk.Frame):    def __init__(self, master, name):        ttk.Frame.__init__(self, master)        self.name = name        self.pack()        self.bind("<Visibility>", self.on_visibility)    def on_visibility(self, event):        self.update()


Instead of

def tab_switch():    # see question...nb.bind("<Button-1>", tab_switch)

you can do the following trick

b.bind("<<NotebookTabChanged>>",        lambda event: event.widget.winfo_children()[event.widget.index("current")].update())

This also removes the need to call

f1.update()  # Initial update of first displayed tab

However, the solution proposed by @BryanOakley might work better when you have different types of frames where you cannot be sure if an .update() method exists.