KivyMD MDDialog 不允许在一个对话框中输入多个文本
我正在与 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()
这是生成的对话框:
每项检查都应有一个文本框,但唯一获得文本框的是底行,无论对话框中有多少项(均测试了 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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,您没有明确指定
MDTextField
的位置。这就是为什么即使它们在那里,它们也只是在父级的默认pos
上相互堆叠。因此,解决方法是将其
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 defaultpos
.So the fix is declare their
pos
explicitly as,