我无法让 Kivy 屏幕管理器在这个特定的应用程序中工作,我已经让它在其他程序中工作了我真的无法让它在这个应用程序中工作

问题描述

所以我正在学习 kivy,我希望有一个按钮将我带到不同的屏幕,以便能够设置闹钟。我制作了另一个文件来学习如何在屏幕和它的工作之间转换,整个上午我一直试图让它在我的另一个应用程序中工作,但我不知道为什么它在这个应用程序中不起作用。该应用程序工作并运行,但是当我单击按钮时没有任何反应。对于任何阅读和帮助我的人,我很感激。

python 文件

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager,Screen
import time



class AlarmWindow(Screen):
    pass

class ClockScreen(Screen):
    def addAlarm(self):
        print("add alarm")

class WindowManager(ScreenManager):
    pass

Builder.load_file('myApp.kv')

class ClockApp(App):

    def build(self):
        return ClockScreen()

    def on_start(self):
        Clock.schedule_interval(self.updateClock,1)

    def updateClock(self,*args):
        print(args)
        #create time variable,if var doesnt work here create it in the ClockScreen class and call it here
        hour = time.strftime("%H")
        minute = time.strftime("%M")
        clockTime = f'{hour}:{minute}'
        #update label
        self.root.ids.clock.text = clockTime

ca = ClockApp()
ca.run()

kv 文件

WindowManager:
    ClockScreen:
    AlarmWindow:

<ClockScreen>:
    name: "main"

    FloatLayout:
        size: root.width,root.height

        Label:
            id: clock
            text: "12:00"
            font_size: 32

        Button:
            text: "Add Alarm"
            size_hint: None,None
            size: 150,100
            pos_hint: {'center_x': .5,'center_y': 0.3}
            on_release: app.root.current = 'second'

<AlarmWindow>:
    name: "second"
    FloatLayout:
        size: root.width,root.height

        Label:
            text: "Create alarm here"

        Button:
            text: "Go Back"
            on_release: app.root.current = 'main'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)