import os
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
kivy.require('1.10.1')
os.environ['KIVY_GL_BACKEND'] = 'sdl2'
class MyApp(App):
def __init__(self, _count=0, **kwargs):
super(MyApp, self).__init__(**kwargs)
self._count = _count
self._change = None
self.txt = None
def increase(self):
self._count += 1
def build(self):
self.title = 'Just an App'
super_box = BoxLayout(orientation='vertical')
horizontal_box = BoxLayout(orientation='vertical')
if not self._change:
self.txt = Button(text='Hello! Just press me!')
self._change = True
def change_text(button):
self.increase()
if not self._change:
button.text = 'Unpressed'
self._change = True
elif self._change:
button.text = 'Pressed'
self._change = False
self.txt.bind(on_press=change_text)
horizontal_box.add_widget(self.txt)
label = Label(text=str(self._count))
horizontal_box.add_widget(label)
super_box.add_widget(horizontal_box)
return super_box
if __name__ == '__main__':
MyApp().run()
Add a code snippet to your website: www.paste.org