Changing color of toggle button text when button is in down and normal state

713 views
Skip to first unread message

KivyNoob

unread,
Mar 9, 2021, 1:40:55 PM3/9/21
to Kivy users support
Hello. I'm having trouble changing the color of a Toggle Button's text when the button state changes from down to up. I'm able to change the color of the text when its in the down state but I can't change the text color back to what it was when it is in the normal state. Does anyone know how to do this? 

Thanks.

Elliot Garbus

unread,
Mar 17, 2021, 7:01:18 PM3/17/21
to kivy-...@googlegroups.com

Here is an example:

Note the highlighted line. 

{'normal': (1,0,1,1), 'down': (1,1,0,1)} [self.state]

This creates a dictionary with 2 keys, normal and down and uses self.state to index into the dict, selecting the color.

 

 

 

from kivy.app import App
from kivy.lang import Builder

kv =
"""
BoxLayout:
    ToggleButton:
        text: 'I am a Toggle'
        color: {'normal': (1,0,1,1), 'down': (1,1,0,1)} [self.state]
"""


class ColorToggle(App):
   
def build(self):
       
return Builder.load_string(kv)
   
    
ColorToggle().run()

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a8ec73e4-839f-40bb-8169-4fc64642ff32o%40googlegroups.com.

 

Reply all
Reply to author
Forward
0 new messages