Skip to content
Advertisement

KivyMD MDDialog is not allowing multiple text inputs to be in one Dialog

I am working with KivyMD and I am trying to create a dialog that has multiple check boxes and multiple text inputs, however I cannot get multiple text inputs to exist in the dialog box

Here is a Minimal Reproducible Example of what I’m talking about:

from kivy.lang import Builder
from kivy.app import App
from kivy.properties import StringProperty
from kivy.uix.screenmanager import Screen

from kivymd.uix.list import  OneLineAvatarIconListItem
from kivymd.app import MDApp
from kivymd.uix.dialog import MDDialog
from kivymd.uix.button import MDFlatButton

Builder.load_string(
    '''
<ImportExcelFile>
    orientation: "horizontal"
    
    CheckboxLeftWidget:
        id: check
        group: "check"
    
    MDTextField:
        id: sheetName
        hint_text: "Sheet Name"
        size_hint_x: None
        width: root.width/3
        pos_hint: {'center_x': 0.5}
        
<FileList>
    MDBoxLayout:
        orientation: 'vertical'
        '''
        )

class ImportExcelFile(OneLineAvatarIconListItem):
    sheet = StringProperty()

class FileList(Screen):
    pass

class MainApp(MDApp):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.screen = FileList()

    def build(self):
        self.importDialogExcel = MDDialog(
            title="Please select the sheets you would like to import, and then give them a name",
            type="confirmation",
            auto_dismiss=False,
            items = [ImportExcelFile(text=f'Sheet {i}', sheet=f'Sheet {i}') for i in range(3)],
            buttons=[
                    MDFlatButton(
                        text="CANCEL",
                        theme_text_color="Custom",
                        text_color=App.get_running_app().theme_cls.primary_color,
                    ),
                    MDFlatButton(
                        text="OK",
                        theme_text_color="Custom",
                        text_color=App.get_running_app().theme_cls.primary_color,
                    ),
                ],
            )
        self.importDialogExcel.open()
        return self.screen

    def on_start(self):
        pass


MainApp().run()

And here is the resulting dialog box:

Example

Each check should have a text box but the only one that is getting one is the bottom row, this happens no matter how many items are in the dialog (2, 3, 4 all tested). With 1 item it works fine

Does anyone know why this could be happening?

Advertisement

Answer

The problem is, you didn’t specify the position of the MDTextField explicitly. That’s why even they’re there, they just stack over each other on the parent’s default pos.

So the fix is declare their pos explicitly as,

    MDTextField:
        id: sheetName
        pos: root.pos
        ...
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement