#python #kivymd
#python #kivymd
Вопрос:
Уже два дня я пытаюсь решить эту проблему. Я пробую почти все. Я 10 раз проверил свои идентификаторы, являются ли они строковыми. Это не так!! Я ввел метод clock.schedule_one для задержки инициализации, но программа не определяет идентификаторы в файле kv. Вот код;
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:UsersMelikşah GÜRCÜDesktopmd.py", line 162, in <module>
DemoApp().run()
File "C:pythonlibsite-packageskivyapp.py", line 855, in run
runTouchApp()
File "C:pythonlibsite-packageskivybase.py", line 504, in runTouchApp
EventLoop.window.mainloop()
File "C:pythonlibsite-packageskivycorewindowwindow_sdl2.py", line 747, in mainloop
self._mainloop()
File "C:pythonlibsite-packageskivycorewindowwindow_sdl2.py", line 479, in _mainloop
EventLoop.idle()
File "C:pythonlibsite-packageskivybase.py", line 339, in idle
Clock.tick()
File "C:pythonlibsite-packageskivyclock.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:UsersMelikşah GÜRCÜDesktopmd.py", line 155, in _press
self.root.ids.hasta.text
File "kivyproperties.pyx", line 863, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'
Ответ №1:
class DemoApp(MDApp):
def _press(self, *dt):
print(self.root.get_screen("scr2").ids.hasta.text)
def _doThis(self, *dt):
print(self.root.get_screen("scr2").ids.hasta.text)