The bool is currently updated when I click on and off the checkbox however when I click the button it will always print the default value I define at the start. How can I update a bool that is outside the class, so that when I click the button and call the function, it updates the bool?
Also, how can I call a function like this when clicking the button, that is outside of the class?
Thanks
someBool = False
def someFunction():
print(someBool)
class MyGridLayout(GridLayout):
def __init__(self, **kwargs):
#grid layout constructor
super(MyGridLayout, self).__init__(**kwargs)
#set columns for the layout
self.cols = 2
self.add_widget(Label(text="checkbox"))
self.checkbox= CheckBox(active = False)
self.add_widget(self.checkbox)
#this will bind the label and checkbox
self.checkbox.bind(active = self.checkboxActive)
self.button= Button(text="Button")
self.button.bind(on_press=someFunction)
self.add_widget(self.button)
def checkboxActive(self, checkbox, value):
if value:
someBool = True
else:
someBool = False
class MyApp(App):
def build(self):
return MyGridLayout()
if __name__ == '__main__':
MyApp().run()
Aucun commentaire:
Enregistrer un commentaire