简体   繁体   English

手动触发TTK笔记本选项卡更改事件

[英]Manually triggering the ttk notebook tab change event

I'm talking about <<NotebookTabChanged>> event that ttk.Notebook can be bound to. 我说的是ttk.Notebook可以绑定到的<<NotebookTabChanged>>事件。 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. 我的意思实际上是说,我有一个基本的选项卡式GUI,并且有一个开始按钮,可在单击该按钮时进行绘图。 There are plots on each tab and when you change tabs, <<NotebookTabChanged>> is triggered, which is an automatically created event by ttk.Notebook . 每个选项卡上都有图,当您更改选项卡时,会触发<<NotebookTabChanged>> ,这是ttk.Notebook自动创建的事件。 I already have a self.tabChanged method for this case. 在这种情况下,我已经有一个self.tabChanged方法。 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 . 我想做的是,我想让我的开始按钮触发此事件,所以我不必只为按钮创建一个新方法,该方法将执行与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. 因此,我需要一种通过单击按钮来触发事件的方法,但是请记住,该事件是ttk.Notebook自己的事件,显然它是设计用于选项卡而不是按钮的。 Is there a way to trigger <<NotebookTabChanged>> manually with a button click? 是否可以通过单击按钮手动触发<<NotebookTabChanged>>

您可以使用event_generate生成虚拟事件(例如,以<<>>开头和结尾的事件):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM