# How to receive tab control event in Python mode

**URL:** <https://discourse.processing.org/t/how-to-receive-tab-control-event-in-python-mode/28944>\
**Category:** Processing.py\
**Created:** [March 29, 2021, 10:26am UTC](https://discourse.processing.org/t/how-to-receive-tab-control-event-in-python-mode/28944 "2021-03-29T10:26:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![uraich](https://avatars.discourse-cdn.com/v4/letter/u/b2d939/32.png) [@uraich](https://discourse.processing.org/u/uraich)\
**Post date:** [March 29, 2021, 10:26am UTC](https://discourse.processing.org/t/how-to-receive-tab-control-event-in-python-mode/28944/1 "2021-03-29T10:26:01Z")

</div>

I have some controlP5 code in Java that I want to port to Python. It uses tabs and captures the control event when the tab is changed. However, in Python I don’t see these events.  
What do I have to do to capture these control events in Python mode?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 29, 2021, 8:51pm UTC](https://discourse.processing.org/t/how-to-receive-tab-control-event-in-python-mode/28944/2 "2021-03-29T20:51:22Z")

</div>

> [@uraich](#):
>
> What do I have to do to capture these control events in Python mode?

> [@How to active ControlEvent in ControlP5 - python Mode?](https://discourse.processing.org/t/how-to-active-controlevent-in-controlp5-python-mode/1113/6):
>
> """ ControlP5::addListener() (v1.1) GoToLoop (2018-Jun-20) https://Discourse.Processing.org/t/ how-to-active-controlevent-in-controlp5-python-mode/1113/6 """ add\_library('controlP5') bg = 0200 def setup(): size(400, 300) global slider slider = ControlP5(this).\ addSlider('slider').\ setSize(width\>\>1, 20).\ setPosition(width\>\>2, height\>\>1).\ setRange(0, 0xff).\ setValue(bg).\ addListener(sliderListe…

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [March 29, 2021, 11:40pm UTC](https://discourse.processing.org/t/how-to-receive-tab-control-event-in-python-mode/28944/3 "2021-03-29T23:40:15Z")

</div>

Also based on wonderful examples by @GoToLoop: 😄

```python
"""
Based on code by GoToLoop
(2018-Jun-20) https://Discourse.Processing.org/t/how-to-active-controlevent-in-controlp5-python-mode/1113/8
"""

add_library('controlP5')

bg = 200
tx = 100

def setup():
    size(400, 300)

    global slider_a, slider_b
    slider_a = (ControlP5(this)
                .addSlider('fundo')
                .setSize(width / 2, 20)
                .setPosition(width / 4, height / 2)
                .setRange(0, 255)
                .setValue(bg)
                .addListener(sliderListener)
                )
    slider_b = (ControlP5(this)
                .addSlider('texto')
                .setSize(width / 2, 20)
                .setPosition(width / 4, 40 + height / 2)
                .setRange(0, 255)
                .setValue(tx)
                .addListener(sliderListener)
                )

def draw():
    background(bg)
    fill(tx)
    text("HELLO SLIDERS", 120, 120)

def sliderListener(evt):
    global bg, tx
    if evt.isFrom(slider_a):
        bg = int(evt.getValue())
    if evt.isFrom(slider_b):
        tx = int(evt.getValue())

```

![sl](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cb46d3f6704c97a80f1ad5c6f9be26fc803bc4d3.gif)

---

<div class="post-metadata">

**Author:** ![uraich](https://avatars.discourse-cdn.com/v4/letter/u/b2d939/32.png) [@uraich](https://discourse.processing.org/u/uraich)\
**Post date:** [March 30, 2021, 7:58am UTC](https://discourse.processing.org/t/how-to-receive-tab-control-event-in-python-mode/28944/4 "2021-03-30T07:58:23Z")

</div>

Thank you very much for your answers. Unfortunately my question was not precise enough: I am not asking for control events in Python in general but I am asking for the control event emitted by the tab class when changing from one tab to the other. There is the method “activateEvent” to which I give the parameter “True” which should make the tab send events when you switch from one tab to the other.  
While I see button or slider events I don’t see this tab event.  
I also tried the lambda way, which also does not see the event.  
The third possibility: adding a callback with cp5.addCallback again works on buttons but I don’t see the tab event.
