自从两天以来,我一直试图解决此问题。我几乎尝试了一切。我检查了我的身份证十次,他们是否是字符串。他们不是!!我将clock.schedule_one方法用于延迟初始化,但程序未在kv文件中定义ID。这是代码;
from kivymd.theming import ThemeManager
from kivymd.app import MDApp
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.tab import MDTabsBase
from kivy.clock import Clock
from kivy.properties import ObjectProperty
from kivy.app import App
Window.size = (300 , 400)
class Screen1(Screen):
pass
class Screen2(Screen):
pass
class Manager(ScreenManager):
pass
Builder.load_string("""
<Manager>:
Screen1:
Screen2:
<Screen1>:
name:"scr1"
BoxLayout:
orientation: 'vertical'
MDToolbar:
title:"ahmet"
MDTabs:
tab_display_mode: "text"
on_tab_switch:app._press
MDTabsBase:
id:hasta
text: "hasta"
MDTabsBase:
id:doktor
text: "doktor"
FloatLayout:
MDRoundFlatIconButton:
on_press:app._doThis
text:"submit"
pos_hint:{"x":0.3,"top":0.7}
FloatLayout:
orientation: 'vertical'
MDTextFieldRound:
id:email
icon_left: "email"
hint_text: "email"
pos_hint:{"x":0.35,"top":0.5}
size_hint:0.3,0.05
MDTextFieldRound:
id:password
icon_left: "password"
hint_text: "password"
pos_hint:{"x":0.35,"top":0.4}
size_hint:0.3,0.05
MDLabel:
multinline:True
text:
"label"
pos_hint:{"x":0.2,"top":0.35}
size_hint:0.6,0.3
font_style:"H6"
font_size:15
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
<Screen2>:
name:"scr2"
BoxLayout:
orientation: 'vertical'
MDToolbar:
text:"ahmet"
MDTabs:
on_tab_switch:app._press
MDTabsBase:
id:hasta
text: "hasta"
MDTabsBase:
id:doktor
text: "doktor"
FloatLayout:
orientation: 'horizontal'
MDRoundFlatIconButton:
on_press:app._doThis
text:"submit"
pos_hint:{"x":0.3,"top":0.7}
FloatLayout:
orientation: 'vertical'
MDTextFieldRound:
id:email
icon_left: "email"
hint_text: "email"
pos_hint:{"x":0.35,"top":0.5}
size_hint:0.3,0.05
MDTextFieldRound:
id:password
icon_left: "password"
hint_text: "password"
pos_hint:{"x":0.35,"top":0.4}
size_hint:0.3,0.05
MDLabel:
multiline:True
text:
"label"
pos_hint:{"x":0.2,"top":0.35}
size_hint:0.6,0.3
font_style:"H6"
font_size:15
theme_text_color: "Custom"
text_color: 0, 0, 1, 1
""")
class DemoApp(MDApp):
def build(self):
Clock.schedule_once(self._press,2)
Clock.schedule_once(self._doThis,2)
return Manager()
def _press(self,*dt):
self.root.ids.hasta.text
def _doThis(self,*dt):
self.root.ids.hasta.text
DemoApp().run()
这是错误消息;
KeyError: 'hasta'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Melikşah GÜRCÜ\Desktop\md.py", line 162, in <module>
DemoApp().run()
File "C:\python\lib\site-packages\kivy\app.py", line 855, in run
runTouchApp()
File "C:\python\lib\site-packages\kivy\base.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "C:\python\lib\site-packages\kivy\core\window\window_sdl2.py", line 747, in mainloop
self._mainloop()
File "C:\python\lib\site-packages\kivy\core\window\window_sdl2.py", line 479, in _mainloop
EventLoop.idle()
File "C:\python\lib\site-packages\kivy\base.py", line 339, in idle
Clock.tick()
File "C:\python\lib\site-packages\kivy\clock.py", line 591, in tick
self._process_events()
File "kivy\_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
File "C:\Users\Melikşah GÜRCÜ\Desktop\md.py", line 155, in _press
self.root.ids.hasta.text
File "kivy\properties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
答案 0 :(得分:0)
{{1}}