So I am trying to take values out of three radio buttons, each having their own boolean assigned to them, and even though my buttons really do change their own values, they don't seem to change the values assigned in the value:
attribute.
This is the python code that handles it:
from kivy.uix.boxlayout import BoxLayout
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.properties import BooleanProperty
from kivy.graphics import *
class CliClicker(BoxLayout):
blue = ObjectProperty(True)
red = ObjectProperty(False)
green = ObjectProperty(False)
def bg_change(self):
#Change background according value set in radio buttons
if self.blue:
print('color changed to blue')
with self.menuoptions.canvas:
Color(rgba=(.7,.7,.9,1))
elif self.red:
print('color changed to red')
with self.menuoptions.canvas:
Color(rgba=(.9,.7,.7,1))
elif self.green:
print('color changed to green')
with self.menuoptions.canvas:
Color(rgba=(.7,.9,.7,1))
def show_value(self, instance, value, box):
self.value = box
print(instance, box, self.value)
print('blue', self.blue)
print('red', self.red)
print('green', self.green)
class MainApp(App):
def build(self):
return CliClicker()
app = MainApp()
app.run()
I included a method that I use to check the state of each value
And this is the Kivy part of the code:
<OptionButton@Button>:
size_hint: (None,None)
width: 200
height: 40
<CliClicker>:
orientation: "vertical"
id: cliclicker
menuoptions: menuopts
TabbedPanel:
do_default_tab: False
height: 200
id: tabs
TabbedPanelItem:
text: "Menu"
id: menu
FloatLayout:
id: menuopts
canvas:
Color:
rgba: .7,.7,.9,1
Rectangle:
pos: self.pos
size: self.size
OptionButton:
text: 'Option 1'
pos_hint: {'right':.63, 'top':.9}
OptionButton:
text: 'Option 1'
pos_hint: {'right':.63, 'top':.8}
GridLayout:
cols: 6
size_hint: (None, None)
pos_hint: {'top': .7, 'right':.69}
height: 40
width: 300
canvas:
Color:
rgba: .9,.9,.9,1
Rectangle:
pos: self.pos
size: self.size
CheckBox:
group: "bg_color"
value: root.blue
on_active: cliclicker.show_value(self, self.value, self.active)
color: 0,0,0,1
Label:
text: 'blue'
color: 0,0,0,1
CheckBox:
group: "bg_color"
value: root.red
on_active: cliclicker.show_value(self, self.value, self.active)
color: 0,0,0,1
Label:
text: 'red'
color: 0,0,0,1
CheckBox:
group: "bg_color"
value: root.green
on_active: cliclicker.show_value(self, self.value, self.active)
color: 0,0,0,1
Label:
text: 'green'
color: 0,0,0,1