I want a pop-up to be created when both a and c are selected in the checkbox.
The popup should show the written: "Both A and C are selected, not well".
I don't want use RadioButton because I want you to be able to select both A and B or B and C
Python file
import kivy
from kivymd.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.core.window import Window
Builder.load_file('try.kv')
class MyLayout(Widget):
checks = []
def checkbox_click(self, instance, value, topping):
if value == True:
MyLayout.checks.append(topping)
print(MyLayout.checks)
if "a" in MyLayout.checks and "c" in MyLayout.checks:
print("not well")
else:
MyLayout.checks.remove(topping)
print(MyLayout.checks)
if "a" in MyLayout.checks and "c" in MyLayout.checks:
print("not well")
class MyApp(App):
def build(self):
return MyLayout()
if __name__ == '__main__':
MyApp().run()
kv file
<MyLayout>
GridLayout:
cols:2
Label:
text:"a"
CheckBox:
on_active: root.checkbox_click(self, self.active, "a")
Label:
text:"b"
CheckBox:
on_active: root.checkbox_click(self, self.active, "b")
Label:
text:"c"
CheckBox:
on_active: root.checkbox_click(self, self.active, "c")
Aucun commentaire:
Enregistrer un commentaire