KivyMD MDDialog 不允许在一个对话框中输入多个文本

发布于 2025-01-13 08:04:26 字数 2293 浏览 0 评论 0原文

我正在与 KivyMD 合作,我正在尝试创建一个具有多个复选框和多个文本输入的对话框,但是我无法在对话框中存在多个文本输入,

这是我正在讨论的最小可重现示例:

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()

这是生成的对话框:

Example

每项检查都应有一个文本框,但唯一获得文本框的是底行,无论对话框中有多少项(均测试了 2、3、4),这种情况都会发生。对于 1 件商品,效果很好

有谁知道为什么会发生这种情况?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷乱花海 2025-01-20 08:04:26

问题是,您没有明确指定 MDTextField 的位置。这就是为什么即使它们在那里,它们也只是在父级的默认 pos 上相互堆叠。

因此,解决方法是将其 pos 显式声明为,

    MDTextField:
        id: sheetName
        pos: root.pos
        ...

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
        ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文