Python 3.x 如何从kivymd中的文本输入中获取数据
我是kivy和kivymd的新手。我想从文本输入中获取文本。但在从按钮调用python文件中的提交函数时遇到了一个问题。我使用了导航抽屉代码。 是否必须在类ContentNavigationDrawer中定义提交函数,或者 类TestNavigationDrawer? 提前谢谢 下面是代码 白痴 .kvPython 3.x 如何从kivymd中的文本输入中获取数据,python-3.x,kivy,kivy-language,kivymd,Python 3.x,Kivy,Kivy Language,Kivymd,我是kivy和kivymd的新手。我想从文本输入中获取文本。但在从按钮调用python文件中的提交函数时遇到了一个问题。我使用了导航抽屉代码。 是否必须在类ContentNavigationDrawer中定义提交函数,或者 类TestNavigationDrawer? 提前谢谢 下面是代码 白痴 .kv 您需要在打印语句中使用self.root.ids.namee.text而不是self.namee.text from kivy.lang import Builder from kivy.uix
您需要在打印语句中使用
self.root.ids.namee.text
而不是self.namee.text
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty, ListProperty
from kivymd.uix.list import OneLineIconListItem, MDList
from kivymd.app import MDApp
class ItemDrawer(OneLineIconListItem):
icon = StringProperty()
text_color = ListProperty((0, 0, 0, 1))
class ContentNavigationDrawer(BoxLayout):
screen_manager = ObjectProperty()
nav_drawer = ObjectProperty()
class TestNavigationDrawer(MDApp):
namee = ObjectProperty()
def build(self):
kv= Builder.load_file("screenmd.kv")
self.theme_cls.primary_palette = "Red"
return kv
def submit(self):
print(self.namee.text)
TestNavigationDrawer().run()
<ContentNavigationDrawer>:
orientation: "vertical"
padding: "8dp"
spacing: "8dp"
AnchorLayout:
anchor_x: "left"
size_hint_y: None
height: avatar.height
Image:
id: avatar
size_hint: None, None
size: "56dp", "56dp"
source: "data/logo/kivy-icon-256.png"
MDLabel:
text: "KivyMD library"
font_style: "Button"
size_hint_y: None
height: self.texture_size[1]
MDLabel:
text: "kivydevelopment@gmail.com"
font_style: "Caption"
size_hint_y: None
height: self.texture_size[1]
ScrollView:
MDList:
OneLineListItem:
text: "Screen 1"
on_press:
root.nav_drawer.set_state("close")
root.screen_manager.current = "scr 1"
OneLineListItem:
text: "Screen 2"
on_press:
root.nav_drawer.set_state("close")
root.screen_manager.current = "scr 2"
Screen:
MDToolbar:
id: toolbar
background_color: app.theme_cls.primary_dark
pos_hint: {"top": 1}
elevation: 10
title: "Iota World"
left_action_items: [["menu", lambda x: nav_drawer.set_state("open")]]
NavigationLayout:
x: toolbar.height
ScreenManager:
id: screen_manager
Screen:
name: "scr 1"
namee:namee
MDTextField:
id:namee
hint_text: "Name"
helper_text:"forget"
pos_hint : {'center_x':0.5 ,'center_y':0.5}
size_hint_x : None
width: 300
MDRectangleFlatButton:
text: "Submit"
pos_hint : {'center_x':0.5 ,'center_y':0.4}
text_color: 0, 0, 1, 1
md_bg_color: 1, 1, 0, 1
on_release:
print("success")
app.submit()
Screen:
name: "scr 2"
MDLabel:
text: "Screen 2"
halign: "center"
MDNavigationDrawer:
id: nav_drawer
ContentNavigationDrawer:
screen_manager: screen_manager
nav_drawer: nav_drawer
id: content_drawer
print(self.namee.text)
AttributeError: 'NoneType' object has no attribute 'text'