KivyMD widgets are displayed at the bottom when using MDBoxLayout. I remember two MDTextField widgets and one MDRaisedButton, but they are located at the bottom. When using Kivy without KivyMD, there is no such problem. Here is my code:
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager
KV = """
ScreenManager:
MDScreen:
name: "main"
MDBoxLayout:
orientation: "vertical"
MDTextField:
hint_text: "User ID"
hint_size: 36
font_size: 36
MDTextField:
hint_text: "Message"
hint_size: 36
font_size: 36
MDRaisedButton:
text: "START"
font_size: 36
increment_width: 100
"""
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
self.root.current = "main"
if __name__ == "__main__":
MainApp().run()
Result: Result of run this code
I tried to replace MDBoxLayout to BoxLayout and MDScreen to Screen, but this not helped.
I solved a problem. I was need to add this to MDBoxLayout:
pos_hint: {"top": 1}
adaptive_height: True
And result code is:
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager
KV = """
ScreenManager:
MDScreen:
name: "main"
MDBoxLayout:
orientation: "vertical"
pos_hint: {"top": 1}
adaptive_height: True
MDTextField:
hint_text: "User ID"
hint_size: 36
font_size: 36
MDTextField:
hint_text: "Message"
hint_size: 36
font_size: 36
MDRaisedButton:
text: "START"
font_size: 36
increment_width: 100
"""
class MainApp(MDApp):
def build(self):
return Builder.load_string(KV)
def on_start(self):
self.root.current = "main"
if __name__ == "__main__":
MainApp().run()
Thanks KivyMD community in KivyMD's Discord!