Stack Overflow на русском Asked by user423190 on February 3, 2021
Вот есть код:
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivymd.app import MDApp
from kivymd.uix.button import MDFlatButton
from kivymd.uix.dialog import MDDialog
KV = '''
<Content>
orientation: "vertical"
spacing: "12dp"
size_hint_y: None
height: "120dp"
MDSwitch:
active: False
FloatLayout:
MDFlatButton:
text: "ALERT DIALOG"
pos_hint: {'center_x': .5, 'center_y': .5}
on_release: app.show_confirmation_dialog()
'''
class Content(BoxLayout):
pass
class Example(MDApp):
dialog = None
def build(self):
return Builder.load_string(KV)
def show_confirmation_dialog(self):
if not self.dialog:
self.dialog = MDDialog(
title="Address:",
type="custom",
content_cls=Content(),
buttons=[
MDFlatButton(
text="CANCEL", text_color=self.theme_cls.primary_color, on_release= self.closeDialog
),
MDFlatButton(
text="OK", text_color=self.theme_cls.primary_color, on_release=self.grabText
),
],
)
self.dialog.set_normal_height()
self.dialog.open()
def grabText(self, inst):
for x in self.dialog.content_cls.children:
print(x.active)
def closeDialog(self, inst):
self.dialog.dismiss()
Example().run()
Но как получить значение не всех дочерних элементов (content_cls.children)
, а только выборочно?
Например, у этого MDSwitch будет id DialogSwitch. Как получить только его значение?
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP