所以我有此代码,其中显示一个kivymd对话框,询问您是否要创建一个新文件夹。有一个文本字段,您可以在其中键入名称,然后单击确定按钮创建文件夹。但是,每当我按下“确定”按钮时,我都不会从文本字段中获取文本。我不知道如何正确访问文本输入的ID。这是创建弹出窗口的类...
class Content(FloatLayout):
def new_folder(self):
self.dialog = MDDialog(
id = "Hello",
title="New Folder",
type="custom",
content_cls=Content(),
buttons=[
MDFlatButton(
text="OK",
on_release =lambda a:Content.create_folder(self))],
radius= (30,30,30,30),
)
self.dialog.open()
return self.dialog
def create_folder(self):
print() ###I want to get the text input of the popup here
以及相应的内容类:
<Content>
id:test
orientation: "vertical"
spacing: "12dp"
size_hint_y: None
height: "50dp"
size_hint_x:None
size:400,40
MDTextField:
id:folder_name
hint_text: "Name:"
helper_text: "Enter a folder name"
helper_text_mode: "on_focus"
recquired: True
pos_hint:{"center_x": .5, "top": 1}
请注意,此功能正在以MainScreen的名称被屏幕调用。如果需要,这里是该类的一部分,调用此函数...
class MainScreen(Screen):
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
Window.bind(on_key_down=self._on_keyboard_down)
#This functions handles executing the necesaary function on click of the quick actions button
def callback(self, instance):
MainScreenvar =sm.get_screen('main_screen')
if instance.icon == 'delete':
Select_Functions.delete_select(self,MainScreenvar.ids.filechooser_icon.selection)
elif instance.icon == 'content-copy':
Select_Functions.copy_select(self,MainScreenvar.ids.filechooser_icon.selection)
elif instance.icon == 'content-cut':
Select_Functions.cut_select(self, MainScreenvar.ids.filechooser_icon.selection)
elif instance.icon == 'folder-plus':
Content.new_folder(self)
这是调用该函数的最后一个省略号。我知道通过实例化(或者我可能是完全错误的;))引起了这个问题,但是我似乎无法弄清楚。谢谢:)
访问文本字段可以通过以下方式检索:
text = self.root.ids.folder_name.text