简体   繁体   English

每次选择某个选项卡时,Gtk Notebook调用功能

[英]Gtk Notebook call function every time a certain tab is selected

I want a tab on my notebook that pretty much does the same like a button. 我希望笔记本上的一个选项卡具有与按钮一样的功能。 Every time I select this tab it should execute a certain job (for example print('something') ). 每次我选择此选项卡时,它都应执行某个作业(例如print('something'))。

How do I get it to execute every time I open it? 如何在每次打开它时执行它? Right now it just executes once on startup and that's it. 现在,它仅在启动时执行一次,仅此而已。

If someone has some advice on this subject I'd really apreciate some help! 如果有人对这个问题有任何建议,我真的很感谢您的帮助!

You're looking for the switch-page signal : 您正在寻找switch-page信号

def callback(notebook, tab, index):
    if index == index_of_the_tab:
        print('selected')

    # alternatively:
    # if tab is the_tab:
    #     print('selected')

notebook.connect('switch-page', callback)

You can use the switch-page signal. 您可以使用switch-page信号。

The callback prototype includes the page number id so that you can figure out to which page you are switching. 回调原型包含页码ID,以便您可以确定要切换到的页面。

void user_function (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data) 无效的user_function(GtkNotebook *笔记本,GtkWidget * page,guint page_num,gpointer user_data)

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

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