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:
JavaScript
x
71
71
1
from kivy.lang import Builder
2
from kivy.app import App
3
from kivy.properties import StringProperty
4
from kivy.uix.screenmanager import Screen
5
6
from kivymd.uix.list import OneLineAvatarIconListItem
7
from kivymd.app import MDApp
8
from kivymd.uix.dialog import MDDialog
9
from kivymd.uix.button import MDFlatButton
10
11
Builder.load_string(
12
'''
13
<ImportExcelFile>
14
orientation: "horizontal"
15
16
CheckboxLeftWidget:
17
id: check
18
group: "check"
19
20
MDTextField:
21
id: sheetName
22
hint_text: "Sheet Name"
23
size_hint_x: None
24
width: root.width/3
25
pos_hint: {'center_x': 0.5}
26
27
<FileList>
28
MDBoxLayout:
29
orientation: 'vertical'
30
'''
31
)
32
33
class ImportExcelFile(OneLineAvatarIconListItem):
34
sheet = StringProperty()
35
36
class FileList(Screen):
37
pass
38
39
class MainApp(MDApp):
40
def __init__(self, **kwargs):
41
super().__init__(**kwargs)
42
self.screen = FileList()
43
44
def build(self):
45
self.importDialogExcel = MDDialog(
46
title="Please select the sheets you would like to import, and then give them a name",
47
type="confirmation",
48
auto_dismiss=False,
49
items = [ImportExcelFile(text=f'Sheet {i}', sheet=f'Sheet {i}') for i in range(3)],
50
buttons=[
51
MDFlatButton(
52
text="CANCEL",
53
theme_text_color="Custom",
54
text_color=App.get_running_app().theme_cls.primary_color,
55
),
56
MDFlatButton(
57
text="OK",
58
theme_text_color="Custom",
59
text_color=App.get_running_app().theme_cls.primary_color,
60
),
61
],
62
)
63
self.importDialogExcel.open()
64
return self.screen
65
66
def on_start(self):
67
pass
68
69
70
MainApp().run()
71
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?
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,
JavaScript
1
5
1
MDTextField:
2
id: sheetName
3
pos: root.pos
4
5