How to unpress a button from python?

726 views
Skip to first unread message

Eric Gaudet

unread,
Sep 25, 2012, 10:26:58 PM9/25/12
to kivy-...@googlegroups.com
Hi,

I'm trying Kivy and I like it very much. I want to build a simple timer app, where I press a togglebutton to start the timer, and when the progressbar is full, the button becomes unpressed (and an alarm sounds, that's easy).

I could not find a way to change the button back to normal. I can read button.state, but setting it doesn't stick. I don't understand why this doesn't work, because the source code of the togglebutton is just setting self.state = 'normal'.

At this point my only option is to call the method _do_press() on my togglebutton, and it works. But my spider senses tell me that I shouldn't call a method with a name starting with '_'.

What is the recommended way of changing the state of a button from python?

Thanks,
EG

Gabriel Pettier

unread,
Sep 26, 2012, 3:37:16 AM9/26/12
to kivy-...@googlegroups.com
> --
>
>
>

setting button.state should work, i just did a simple test
https://gist.github.com/3786608
and it works for me.

Eric Gaudet

unread,
Sep 26, 2012, 12:28:25 PM9/26/12
to kivy-...@googlegroups.com
On 09/26/2012 12:37 AM, Gabriel Pettier wrote:
>
> setting button.state should work, i just did a simple test
> https://gist.github.com/3786608
> and it works for me.
>
Hum, you're right. There must have been another bug in my code. Thanks!

Jason Haury

unread,
Oct 1, 2014, 4:14:46 AM10/1/14
to kivy-...@googlegroups.com
Thanks, Eric, for the gist!  To help future searchers for on this topic, I found this Kivy documentation on the CheckBox to be a bit misleading as it says the "active" (bool) describes which is checked, and claims that a group of CheckBoxes causes the same behavior as a ToggleButton (ie takes on Radio button behavior where only one can be checked or pressed at a time).  As it turns out, the Behaviors documentation is the correct place to look, specifically the ButtonBehavior section. As the CheckBox had the "active" property, the Button has a "state" property (string) which can be either "normal" (unpressed) or "down" (pressed).

Note that even though ToggleButtons behave to the user by only letting one be down at a time, using the Python properties to change their states allows you to have several down at once.  In other words, setting a ToggleButton state to "down" does not set all its siblings to "normal" - one must do that explicitly.
Reply all
Reply to author
Forward
0 new messages