Button Onpress Quit

Date: February 26th 2016
Last updated: February 26th 2016

A quit app action can be handled entirely in the kv file.

main.py

import kivy
kivy.require('1.9.1')
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

class Sample(BoxLayout):
    pass

class SampleApp(App):
    def build(self):
        return Sample()

# Quit app handled by kv file

if __name__ == '__main__':
    SampleApp().run()

sample.kv

#:kivy 1.9.1
<Sample>:
    orientation: 'vertical'

    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Test label at V1 position'
        ToggleButton:
            text: 'Test ToggleButton at V2 position'

    BoxLayout:
        orientation: 'horizontal'
        size_hint: 1, 0.4
        Button:
            text: 'Play'
        Button:
            text: 'Reset'
        Button:
            text: 'Quit' #<===== text label
            on_press: app.stop() #<===== action
            background_color: 1,0,0,1 #<===== color

Output

onpress quit application button screenshot

results matching ""

    No results matching ""