1app.py:
2
3import kivy
4from kivy.app import App
5from kivy.uix.boxlayout import BoxLayout
6from kivy.uix.button import Button
7
8class Launch(BoxLayout):
9 def __init__(self, **kwargs):
10 super(Launch, self).__init__(**kwargs)
11
12 def say_hello(self): #<---- function that the button is calling
13 print "hello"
14
15
16class App(App):
17 def build(self):
18 return Launch()
19
20
21if __name__ == '__main__':
22 App().run()
23
24app.kv:
25
26#:kivy 1.9.1
27
28<Launch>:
29 BoxLayout:
30 Button:
31 size:(80,80)
32 size_hint:(None,None)
33 text:"Click me"
34 on_press: say_hello() #<--- calls the say_hello() function
1import kivy
2from kivy.uix.widget import Widget
3from kivy.lang import Builder
4from kivymd.app import MDApp
5
6Builder.load_file('foo.kv')
7
8class layout1(Widget):
9 pass
10class App(MDApp):
11 def build(self):
12 self.theme_cls.theme_style = "Dark"
13 self.theme_cls.primary_palette = "BlueGray"
14 return layout1()
15 def themeSwitch(self):# function that will be called from layout1() class
16 pass
17
18
19#kv file from here on.
20<layout1>
21 BoxLayout:
22 Button:
23 size_hint:(None,None)
24 size:(80,80)
25 text:"Click me"
26 on_press: app.themeSwitch()