Remarques:
ou
Dans geany, ouvrir tous les fichiers et Excécuter les .py
classique.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class ClassiqueApp(App): def build(FloatLayout): pass if __name__ == '__main__': ClassiqueApp().run()
classique.kv
#:kivy 1.8.0 GridLayout: cols: 4 rows: 3 padding: 10 Label: text: "Je suis un label" Button: text: "bouton 1" CheckBox: active: True Image: source: 'softboy.png' Slider: min: -100 max: 100 value: 25 ProgressBar: min: 0 max: 1000 TextInput: text: "Saisir un texte" ToggleButton: text: "Mode poésie" Switch: active: True Video: source: "softboy.avi" play: True
Les éléments sont ancrés sur un point
anchorlayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class AnchorlayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': AnchorlayoutApp().run()
anchorlayout.kv
#:kivy 1.8.0 AnchorLayout: anchor_x: 'right' anchor_y: 'bottom' padding: 50 Button: size_hint: 0.3, 0.4 text: "bouton 1" Label: size_hint: 0.7, 0.6 text: "Je suis ancré"
Empilement de boîtes horizontales ou verticales.
boxlayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class BoxlayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': BoxlayoutApp().run()
boxlayout.kv
#:kivy 1.8.0 BoxLayout: spacing: 10 padding: 10 orientation: "horizontal" Button: text: "bouton 1" Button: text: "bouton 2" Button: size_hint_y: 0.3 text: "bouton 3" BoxLayout: spacing: 10 padding: 10 orientation: "vertical" Button: size_hint_y: 0.5 text: "bouton 4" Button: size_hint_y: 0.4 text: "bouton 5" Button: size_hint_y: 0.3 text: "bouton 6" Button: text: "bouton 7"
Défini une grille avec des lignes et des colonnes.
gridlayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class GridlayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': GridlayoutApp().run()
gridlayout.kv
#:kivy 1.8.0 GridLayout: spacing: 10 padding: 10 cols: 2 rows: 2 Button: text: "bouton 1" Button: text: "bouton 2" Button: text: "bouton 3" GridLayout: spacing: 10 padding: 10 cols: 2 rows: 2 Button: size_hint_y: 0.5 text: "bouton 4" Button: size_hint_y: 0.4 text: "bouton 5" Button: size_hint_y: 0.3 text: "bouton 6" Button: text: "bouton 7"
pagelayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class PagelayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': PagelayoutApp().run()
pagelayout.kv
#:kivy 1.8.0 PageLayout: Button: text: 'page1' Button: text: 'page2' Button: text: 'page3'
stacklayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class StacklayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': StacklayoutApp().run()
stacklayout.kv
#:kivy 1.8.0 StackLayout: spacing: 10 padding: 10 orientation: 'tb-rl' Button: text: "bouton 1" size_hint: 0.3, 0.5 Button: text: "bouton 2" size_hint: 0.2, 0.2 Button: text: "bouton 3" size_hint: 0.15, 0.2
Retourne des coordonnées relatives
relativelayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class RelativelayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': RelativelayoutApp().run()
relativelayout.kv
#:kivy 1.8.0 BoxLayout: Label: text: 'Left' Button: text: 'Middle' on_touch_down: print('Middle: {}'.format(self.to_local(*args[1].pos))) RelativeLayout: on_touch_down: print('Relative: {}'.format(self.to_local(*args[1].pos))) Button: text: 'Right' on_touch_down: print('Right: {}'.format(self.to_local(*args[1].pos)))
Permet de déplacer des widgets.
scatterlayout.py
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import kivy kivy.require('1.8.0') from kivy.app import App from kivy.core.window import Window Window.size = (1120, 630) class ScatterlayoutApp(App): def build(FloatLayout): pass if __name__ == '__main__': ScatterlayoutApp().run()
scatterlayout.kv
#:kivy 1.8.0 FloatLayout: ScatterLayout: Label: size_hint: 0.2, 0.2 text: 'Left' Label: size_hint: 0.2, 0.5 text: 'Middle' ScatterLayout: Label: size_hint: 0.5, 0.2 text: 'Right'
Défilement d'une liste de ligne
class MainScreen(Screen): text = StringProperty("Mon Texte") def __init__(self, **kwargs): super().__init__(**kwargs) self.text = "Mon texte\n"*100
<MainScreen>: BoxLayout: orientation: "vertical" ScrollView: do_scroll_x: False do_scroll_y: True Label: id: scroll size_hint: None, None # très important ! size: self.texture_size height: self.size[1] width: self.size[0] padding: 10, 10 text: root.text color: 1, 0, 0.5, 1 font_size: "20dp"