#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:
center: self.parent.center
size_hint: None, None
size: label_id.size
canvas.after:
Color:
rgba: 1, 0, 0, 0.5
Rectangle:
size: self.size
pos: self.pos
Label:
id: label_id
text: textinput_id.text
font_size: 150
color: root.text_colour
size: self.texture_size
canvas:
Color:
rgba: 0, 1, 0, 0.5
Rectangle:
pos: self.pos
size: self.size
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
-----------------------
#main.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import random
from kivy.graphics.vertex_instructions import (Rectangle, Ellipse, Line)
from kivy.graphics.context_instructions import Color
from kivy.properties import ListProperty, ObjectProperty
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()
reference:
No comments:
Post a Comment