rawpython / remi

Python REMote Interface library. Platform independent. In about 100 Kbytes, perfect for your diet.
Apache License 2.0
3.51k stars 401 forks source link

Onclick when changing tabs in TabBox #533

Closed VP1701 closed 2 months ago

VP1701 commented 2 months ago

Is there a way for having some kind of a onclick or onchange method to trigger methods when changing tabs? I'm showing data on different tabs and I would like to stop the update methods for different tabs when I'm not looking at them.

dddomodossola commented 2 months ago

Hello @VP1701 ,

here is an example for you:

import remi.gui as gui
from remi import start, App

class MyApp(App):
    def __init__(self, *args):
        super(MyApp, self).__init__(*args)

    def main(self):
        tb = gui.TabBox(width='80%')
        tb.append(gui.Label("tab 1"), 'First')
        tb.add_tab(gui.Label("tab 2"), 'Second', None)
        tb.add_tab(gui.Label("tab 3"), 'Third', None)

        tb.on_tab_selection.do(self.on_tab_selection)

        return tb

    def on_tab_selection(self, widget, tab_key):
        print("tab selected:", tab_key)

if __name__ == "__main__":
    start(MyApp, title="Tab Demo")

have a nice day

VP1701 commented 2 months ago

Thank you. this helped a lot.