KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
# Working Example
from kivymd.app import MDApp
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.textfield import MDTextField, MDTextFieldHelperText
class TestApp(MDApp):
def build(self):
return MDFloatLayout(
md_bg_color=self.theme_cls.surfaceColor,
)
def on_start(self):
self.root.add_widget(
MDTextField(
MDTextFieldHelperText(text="Helper Text", mode="persistent"),
pos_hint={"center": (0.5, 0.5)},
)
)
if __name__ == "__main__":
TestApp().run()
This code will produce an app with a single MDTextField at the center. The text field will have a helper text displaying "Helper Text". So far everything works fine. But now take a look at the following:
# Faulty Example
from kivymd.app import MDApp
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.uix.floatlayout import MDFloatLayout
from kivymd.uix.textfield import MDTextField, MDTextFieldHelperText
class TestApp(MDApp):
def build(self):
return MDFloatLayout(
MDButton(
MDButtonText(text="Show text field"),
on_release=self.display,
),
md_bg_color=self.theme_cls.surfaceColor,
)
def display(self, *_):
self.root.add_widget(
MDTextField(
MDTextFieldHelperText(text="Helper Text", mode="persistent"),
pos_hint={"center": (0.5, 0.5)},
)
)
if __name__ == "__main__":
TestApp().run()
This app is almost the same as the one above, except that you first have to click the button in the bottom left before the text field appears. However, once the text field has appeared it does not display a helper text.
Side Note:
If you assign the MDTextField to a variable and then call its apply_class_lang_rules method without any arguments, the helper text will actually show up. This is not exactly a fix though, because for a text field with mode="on_error" this would make the helper text show until the text field first receives focus, even if no error is present. After that the helper text will behave as intended.
Description of the Bug
Consider the example below:
This code will produce an app with a single
MDTextField
at the center. The text field will have a helper text displaying"Helper Text"
. So far everything works fine. But now take a look at the following:This app is almost the same as the one above, except that you first have to click the button in the bottom left before the text field appears. However, once the text field has appeared it does not display a helper text.
Side Note:
If you assign the
MDTextField
to a variable and then call itsapply_class_lang_rules
method without any arguments, the helper text will actually show up. This is not exactly a fix though, because for a text field withmode="on_error"
this would make the helper text show until the text field first receives focus, even if no error is present. After that the helper text will behave as intended.Versions