The short answer is you don’t.
The id is a kv capability. When the kv file is processed, the ids dict is populated.
You can address specific widgets or walk the widget tree. I added some exampled below:
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.button import MDFlatButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.textfield import MDTextField
class Example(MDApp):
dialog = None
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return (
MDFloatLayout(
MDFlatButton(
text="ALERT DIALOG",
pos_hint={'center_x': 0.5, 'center_y': 0.5},
on_release=self.show_confirmation_dialog,
)
)
)
def show_confirmation_dialog(self, *args):
if not self.dialog:
self.dialog = MDDialog(
title="Address:",
type="custom",
content_cls=MDBoxLayout(
MDTextField(
hint_text="City",
),
MDTextField(
hint_text="Street",
),
orientation="vertical",
spacing="12dp",
size_hint_y=None,
height="120dp",
),
buttons=[
MDFlatButton(
text="CANCEL",
theme_text_color="Custom",
text_color=self.theme_cls.primary_color,
),
MDFlatButton(
text="OK",
theme_text_color="Custom",
text_color=self.theme_cls.primary_color,
),
],
)
self.dialog.open()
print(f'{self.dialog.content_cls=}')
print(f'{self.dialog.content_cls.children}')
self.dialog.content_cls.children[0].text = '200 Main Street'
self.dialog.content_cls.children[1].text = 'Anytown'
print('-' * 80)
for w in self.dialog.walk(restrict=True): # widgets under dialog
print(w)
print('-' * 80)
for w in self.dialog.walk(restrict=True):
if isinstance(w, MDTextField):
print(f'TextFiled: {w}', end=' ')
if w.hint_text == 'City':
print('The City TextInput')
if w.hint_text == 'Street':
print('The Street TextInput')
Example().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a42c41c9-a5ff-4ca1-86df-6b2b03ec5d05n%40googlegroups.com.