Appearance of Switch/Checkbox Widgets

1,912 views
Skip to first unread message

just_jake

unread,
Jul 18, 2012, 5:04:37 PM7/18/12
to kivy-...@googlegroups.com
I have looked around for ways to change the appearance of certain types of widgets, including the Switch and Checkbox widgets, and couldn't find any. Is there a way to do this easily, or would the Kivy source/image files themselves need to be modified? If these files are modified, what kind of license and distribution ramifications would that have for a commercial application? Apologies if I'm overlooking something obvious.

Akshay Arora

unread,
Jul 19, 2012, 5:25:52 AM7/19/12
to kivy-...@googlegroups.com
You could simply over ride the default appearance by changing it in the kv something like this.


#imports
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.checkbox import CheckBox
from kivy.lang import Builder
from kivy.factory import Factory

class CCheckBox(CheckBox):
    pass

Factory.register('CCheckBox', cls=CCheckBox)

Builder.load_string("""
<CCheckBox>:
    canvas:
        Clear:
        Color:
            rgba: 1, .5, 1, .5
        Rectangle:
            size: 32, 32
            pos: int(self.center_x - 16), int(self.center_y - 16)
        Color:
            rgba: 1, 1, 0, 1
        Rectangle:
            source: 'atlas://data/images/defaulttheme/checkbox%s_%s' % (('_radio' if self.group else ''), ('on' if self.active else 'off'))
            size: 32, 32
            pos: int(self.center_x - 16), int(self.center_y - 16)

<SMApp>:
    CCheckBox:
    Switch:
""")

class SMApp(App, BoxLayout):

    def build(self):
        return self


if __name__ == '__main__':
    SMApp().run()

If you want to change the appearance globally for all the kivy apps you can look inside kivy_install_dir/kivy/data/style.kv and grep for the widget you need to change the appearance of.

Of-course if you are just looking to change the theme style for the entire kivy widget set, you can look at changing the default theme atlas in kivy_install_dir/kivy/data/images/defaulttheme-0.png

On Thu, Jul 19, 2012 at 2:34 AM, just_jake <halfto...@gmail.com> wrote:
I have looked around for ways to change the appearance of certain types of widgets, including the Switch and Checkbox widgets, and couldn't find any. Is there a way to do this easily, or would the Kivy source/image files themselves need to be modified? If these files are modified, what kind of license and distribution ramifications would that have for a commercial application? Apologies if I'm overlooking something obvious.

--
 
 
 

gabriel pettier

unread,
Jul 19, 2012, 5:40:58 AM7/19/12
to kivy-...@googlegroups.com
> --
>
>
>

As for the licences implications, subclassing would have no implication
to my knowledge, as opposed to changing style.kv or defaulttheme-0.png
would be more like a derivative work, thus requiring contributions of
the new versions, i think. In any way your client code using kivy or
your modified version of kivy is not impacted by any of this, your code
is your.

Thomas Hansen

unread,
Jul 19, 2012, 9:17:18 AM7/19/12
to kivy-...@googlegroups.com
You can just overwrite the rule in you own kv. You can add a Clear
instruction at the beginning of canvas to remove anything added by the
default rule.

Sent from my iPhone
> --
>
>
>

just_jake

unread,
Jul 19, 2012, 11:33:29 AM7/19/12
to kivy-...@googlegroups.com
Thank you all for your responses! This was the last thing holding me back from starting a project with Kivy; I'm looking forward to diving in.
Reply all
Reply to author
Forward
0 new messages