Manually triggering the ttk notebook tab change event

1.3k views Asked by At

I'm talking about <<NotebookTabChanged>> event that ttk.Notebook can be bound to. Say I have:

def tabChanged(self, event):
    print "tab changed"

And say I want to manually trigger this method. What I actually mean by this is, say I have a basic, tabbed GUI and there's a start button which makes plots when you click it. There are plots on each tab and when you change tabs, <<NotebookTabChanged>> is triggered, which is an automatically created event by ttk.Notebook. I already have a self.tabChanged method for this case. What I wanna do is, I wanna make my start button trigger this event so I don't have to create a new method just for the button which will do the exact same thing as self.tabChanged. So I need a way of triggering the event through a button click, but remember, that event is ttk.Notebook's own event and apparently it was designed to be used with tabs, not buttons. Is there a way to trigger <<NotebookTabChanged>> manually with a button click?

1

There are 1 answers

1
Bryan Oakley On BEST ANSWER

You can generate virtual events (eg: events that begin and end with << and >>) with event_generate:

self.the_notebook.event_generate("<<NotebookTabChanged>>")