python - 如何从 MDbutton 中的 on_release 触发 MDTextField 中的 on_text_validate?
问题描述
我想on_text_validate:
在我的 MDTextField 中触发:通过一个按钮。我试图通过on_release:
在我的MDRaisedButton:
. 我试过了,但没有用
ScreenManager:
HomeScreen:
ResultScreen:
<HomeScreen>:
name: 'home'
BoxLayout:
orientation: 'vertical'
spacing: '15dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
BoxLayout:
orientation: 'vertical'
MDLabel:
MDTextField:
id: userinput
hint_text: 'DOB in "DD/MM/YYYY" Format'
helper_text: 'Invalid Entry'
helper_text_mode: 'on_error'
size_hint_x: None
width: '225dp'
pos_hint: {"center_x": 0.5}
halign: 'center'
on_quad_touch: None
on_text: None
on_text_validate:
root.inputtextfn()
root.text_validate()
root.manager.current = 'result' if self.error is False else 'home'
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
id: btn
text: 'SUBMIT'
font_size: '15dp'
elevation: 12
md_bg_color: app.theme_cls.primary_color
pos_hint: {"center_x": 0.5}
on_release:
#root.ids.userinput.bind(on_text_validate=self.on_release)
#root.ids.userinput.on_text_validate() == True
MDLabel:
MDLabel:
<ResultScreen>:
name: 'result'
BoxLayout:
orientation: 'vertical'
spacing: '75dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["keyboard-backspace", lambda x: app.set_homescreen() ]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
type: 'top'
pos_hint: {"top":1}
MDLabel:
请帮助代码中的注释行。
解决方案
回答我自己的问题……哈哈。这个问题简单写就解决了
root.ids.userinput.dispatch('on_text_validate')
它起作用了on_release:
,现在代码看起来像这样......
ScreenManager:
HomeScreen:
ResultScreen:
<HomeScreen>:
name: 'home'
BoxLayout:
orientation: 'vertical'
spacing: '15dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["menu", lambda x: app.navigation_draw()]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
BoxLayout:
orientation: 'vertical'
MDLabel:
MDTextField:
id: userinput
hint_text: 'DOB in "DD/MM/YYYY" Format'
helper_text: 'Invalid Entry'
helper_text_mode: 'on_error'
size_hint_x: None
width: '225dp'
pos_hint: {"center_x": 0.5}
halign: 'center'
on_quad_touch: None
on_text: None
on_text_validate:
root.inputtextfn()
root.text_validate()
root.manager.current = 'result' if self.error is False else 'home'
BoxLayout:
orientation: 'vertical'
MDRaisedButton:
id: btn
text: 'SUBMIT'
font_size: '15dp'
elevation: 12
md_bg_color: app.theme_cls.primary_color
pos_hint: {"center_x": 0.5}
on_release:
root.ids.userinput.dispatch('on_text_validate')
MDLabel:
MDLabel:
<ResultScreen>:
name: 'result'
BoxLayout:
orientation: 'vertical'
spacing: '75dp'
MDToolbar:
title: 'Age Calculator'
left_action_items: [["keyboard-backspace", lambda x: app.set_homescreen() ]]
right_action_items: [["dots-vertical", lambda x: app.info()]]
elevation: 20
type: 'top'
pos_hint: {"top":1}
MDLabel:
推荐阅读
- spring - Spring外事务失败回滚内事务
- xamarin - 如何在 Xamarin Forms 中执行功能之前加载视图页面?
- .net - Azure Cosmos DB - 删除整个分区
- excel - excel结合if语句和stdev
- python - model_main.py 不适用于使用旧指南创建的自己的数据集
- c++ - 如何使用 OpenGL 和 C++ 加载多个纹理?
- laravel - Laravel Eloquent:保存数据的嵌套关系
- xml - 防止 IIS 6.2 中的 XML 缓存
- diff - 如何在 Perforce/P4V 中使用 010 编辑器比较文件
- python - EC2 SSH 进入其他 SSH 并运行 bash 脚本