on_press: MyCustomlabel_id.text = self.text
NameError: name 'MyCustomlabel_id' is not defined
<Custombutton@Button>:
background_color: 0,1,0,1
background_normal: ''
bold: True
color: 1,0,1,1
on_press: MyCustomlabel_id.text = self.text
<MyCustomlabel@Label>:
color: 1,0,0,1
font_size: self.width * .1
italic : True
id: MyCustomlabel_id
BoxLayout:
MyCustomlabel:
id : MyCustomlabel_id
Custombutton:
text: 'text1'
Custombutton:
text: 'text2'
Custombutton:
text: 'text3'
The id must refer to a widget instance. You can also use them to refer to widgets within a compound widget.
Each kv-rule defines a different ids name space.
In the example below the class TwoLabels has two id’s, top and bottom. An instance of TwoLabels is created and given the id two_labels. The id dict of the two_labels instance is accessed and used to address the sub widgets in the class instance.
two_lables.ids.top.text
from kivy.app import App
from kivy.lang import Builder
kv = """
<CustomButton@Button>:
background_color: 0,1,0,1
background_normal: ''
bold: True
color: 1,0,1,1
<MyCustomLabel@Label>:
color: 1,0,0,1
font_size: self.width * .1
italic : True
<TwoLabels@BoxLayout>
orientation: 'vertical'
Label:
id: top
text: 'top: Initial text'
Label:
id: bottom
text: 'bottom: Initial text'
BoxLayout:
MyCustomLabel:
id: mcl_1
CustomButton:
text: 'text 1'
on_release: mcl_1.text = self.text
CustomButton:
text: 'text 2'
on_release: mcl_2.text = self.text
CustomButton:
text: 'text 3'
on_release: two_labels.ids.top.text = self.text
CustomButton:
text: 'text 4'
on_release: two_labels.ids.bottom.text = self.text
TwoLabels:
id: two_labels
MyCustomLabel:
id: mcl_2
"""
class TestIDSApp(App):
def build(self):
return Builder.load_string(kv)
TestIDSApp().run()
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d0de7aac-2b39-4b6a-9ad9-c6b3814d69bd%40googlegroups.com.