0

so i'm learning kivy and I want to have a button bring me to a different screen to be able to set a alarm. I've made another file to learn how to transition between screens and its worked and all morning I've been trying to get it to work in my other app and I cant figure out why it wont work in this app. The app works and runs but when I click the button nothing happens. For anyone reading and helping me I appreciate it.

python file

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 file

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'
scorpio
  • 61
  • 1
  • 8
  • I started from scratch and fixed it but to anyone willing to answer im still curious what was going wrong with the previous version I made. – scorpio Feb 11 '21 at 18:12
  • The `return ClockScreen()` in your `build()` method is making the `ClockScreen` the `app.root`, so your app has no `WindowManager`. Try replacing that line with `return Builder.load_file('myApp.kv')` and remove the other `Builder.load_file()` line. – John Anderson Feb 11 '21 at 19:17
  • Awesome! I appreciate the help, thanks. – scorpio Feb 11 '21 at 20:22

0 Answers0