Skip to content

Commit

Permalink
Merge pull request kivy#3154 from picibucor/picibucor
Browse files Browse the repository at this point in the history
examples added
  • Loading branch information
dessant committed May 15, 2015
2 parents 8009ba9 + 4a7e6dd commit aeeac3e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/kv/ids/id_in_kv/id_in_kv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'''
The use of id in .kv
==================================
This small example shows how to refer from one widget
on an other widget within .kv
'''
from kivy.app import App

import kivy
kivy.require('1.8.0')


class TestApp(App):
pass

if __name__ == '__main__':
TestApp().run()
11 changes: 11 additions & 0 deletions examples/kv/ids/id_in_kv/test.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#:kivy 1.8.0

BoxLayout:
orientation: 'vertical'
TextInput:
# setting the id of the widget
id: my_id
text: 'The text of the label is set within kivy'
Label:
# showing the text of the textinput by referring on the id
text: my_id.text
33 changes: 33 additions & 0 deletions examples/kv/ids/kv_and_py/kv_and_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'''
Referring on ids from .py
==================================
This example shows how to refer to an id from a .py file.
'''
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

import kivy
kivy.require('1.8.0')


class RootWidget(BoxLayout):

def first_function(self, status):
# print out the given parameter
print(status)
# check the status of the switch by referring on the id
if self.ids.my_switch.active is True:
# set the text of the label by referring on the id
self.ids.my_label.text = 'Switch is ON'
else:
# set the text of the label by referring on the id
self.ids.my_label.text = 'Switch is OFF'


class TestApp(App):
pass


if __name__ == '__main__':
TestApp().run()
12 changes: 12 additions & 0 deletions examples/kv/ids/kv_and_py/test.kv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#:kivy 1.0

RootWidget:
BoxLayout:
orientation: 'vertical'
Switch:
id: my_switch
on_active: root.first_function(self.active)

Label:
id: my_label
text: 'This text will be changed by the python file'

0 comments on commit aeeac3e

Please sign in to comment.