如何解决此AttributeError :?

时间:2019-10-31 22:12:33

标签: python-3.x kivy kivy-language

我收到AttributeError :,我知道问题出在我的.kv文件的23上,但是我不知道如何解决它,我该如何制作我的根窗口小部件,以便程序能够正常工作。

*。py

from kivy.app import App
from kivymd.theming import ThemeManager
from kivy.app import App
from datetime import datetime
from datetime import timedelta
from kivy.clock import Clock
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivymd.theming import ThemeManager


class Login_Screen(Screen):
    pass

class Homepage_Screen(Screen):
    pass


class Application_Screen(Screen):
    pass


class ScreenManagement(ScreenManager):
    pass



class MainApp(App):
    def build(self):
        self.now = datetime.now()
        Clock.schedule_interval(self.update_clock, 1)

    def update_clock(self, *args):
        self.now = self.now + timedelta(seconds=1)
        self.root.get_screen("Homepage_Screen").ids["CurrentTime"].text = self.now.strftime("%H:%M:%S")
        #self.root.get_screen("Homepage_Screen").ids["CurrentTime"].text = self.now.strftime("%H:%M:%S")
        print(self.now.strftime("%H:%M:%S"))
    theme_cls = ThemeManager()


MainApp().run()

.kv

#:kivy 1.0
ScreenManagement:
    #Login_Screen:
        #name:"Login_Screen"
    Homepage_Screen:
        name:"Homepage_Screen"
    Application_Screen:
        name:"Application_Screen"
<Homepage_Screen>:
    NavigationLayout:
        MDNavigationDrawer:
            NavigationDrawerIconButton:
                text: "Screen 1"
            NavigationDrawerIconButton:
                text: "Screen 2"
                on_release:
                    screen_manager.current = "screen2"
        BoxLayout:
            orientation: 'vertical'
            MDToolbar:
                title: "Your app"
                md_bg_color: app.theme_cls.primary_color
                left_action_items: [['menu', lambda x: root.toggle_nav_drawer()]]
                Label:
                    id: CurrentTime
            ScreenManager:
                id: screen_manager
                Screen:
                    name: "screen1"
                    MDLabel:
                        text: "Screen 1"
                Screen:
                    name: "screen2"
                    MDLabel:
                        text: "Screen 2"

我希望能够单击菜单按钮(左上角)打开侧面菜单,但是每次都会崩溃。我可以单击并拖动以获取菜单,但菜单按钮崩溃。

0 个答案:

没有答案