การพิมพ์ครั้งที่ 1
การพิมพ์ครั้งที่ 2
การพิมพ์ครั้งที่ 3
def my_callback(dt): pass # call my_callback every 0.5 seconds event = Clock.schedule_interval(my_callback, 0.5) # call my_callback in 5 seconds event2 = Clock.schedule_once(my_callback, 5) event_trig = Clock.create_trigger(my_callback, 5) event_trig() # unschedule using cancel event.cancel() # unschedule using Clock.unschedule Clock.unschedule(event2) # unschedule using Clock.unschedule with the callback # NOT RECOMMENDED Clock.unschedule(my_callback)def my_callback(dt):
pass # call my_callback every 0.5 seconds event = Clock.schedule_interval(my_callback, 0.5) # call my_callback in 5 seconds event2 = Clock.schedule_once(my_callback, 5) event_trig = Clock.create_trigger(my_callback, 5) event_trig() # unschedule using cancel event.cancel() # unschedule using Clock.unschedule Clock.unschedule(event2) # unschedule using Clock.unschedule with the callback # NOT RECOMMENDED Clock.unschedule(my_callback)
from kivy.uix.screenmanager import ScreenManager, Screen # Create the manager sm = ScreenManager() # Add few screens for i in range(4): screen = Screen(name='Title %d' % i) sm.add_widget(screen) # By default, the first screen added into the ScreenManager will be # displayed. You can then change to another screen. # Let's display the screen named 'Title 2' # A transition will automatically be used. sm.current = 'Title 2'
from kivy.app import App from kivy.lang import Builder from kivy.uix.screenmanager import ScreenManager, Screen Builder.load_string(""" <MenuScreen>: BoxLayout: Button: text: 'Goto settings' on_press: root.manager.current = 'settings' Button: text: 'Quit' <SettingsScreen>: BoxLayout: Button: text: 'My settings button' Button: text: 'Back to menu' on_press: root.manager.current = 'menu' """) # Declare both screens class MenuScreen(Screen): pass class SettingsScreen(Screen): pass # Create the screen manager sm = ScreenManager() sm.add_widget(MenuScreen(name='menu')) sm.add_widget(SettingsScreen(name='settings')) class TestApp(App): def build(self): return sm if __name__ == '__main__': TestApp().run()