#main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import random
from kivy.properties import ListProperty
class ScatterTextWidget(BoxLayout):
text_colour = ListProperty([1, 0, 0, 1])
def change_label_colour(self, *args):
colour = [random.random() for i in [0,1,2]] + [1]
print(colour)
self.text_colour = colour
class TutorialApp(App):
def build(self):
return ScatterTextWidget()
TutorialApp().run()
-----------------------
#tutorial.kv
#:import random random
<ScatterTextWidget>:
orientation: 'vertical'
TextInput:
id: textinput_id
font_size: 150
size_hint_y: None
height: 200
text: 'default'
on_text: root.change_label_colour()
#on_text: label_id.color = [random.random() for i in [0,1,2]] + [1]
FloatLayout:
Scatter:
Label:
id: label_id
text: textinput_id.text
font_size: 150
color: root.text_colour
BoxLayout:
orientation: 'horizontal'
size_hint_y: None
height: 150
Label:
id: label1
text: textinput_id.text[:3]
font_size: 100
color: root.text_colour
Label:
id: label2
text: textinput_id.text[-3:]
font_size: 100
color: root.text_colour
reference:
No comments:
Post a Comment