#project structure
main.py
tutorial.kv
#main.py
from kivy.uix.boxlayout import BoxLayout
import random
class ScatterTextWidget(BoxLayout):
def change_label_colour(self, *args):
colour = [random.random() for i in [0,1,2]] + [1]
print(colour)
label = self.ids['label_id']
label.color = 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
-----------------
#logs
[0.1348179395731689, 0.24583291893163917, 0.9907235899551307, 1]
[0.2874682150281308, 0.9696246742617654, 0.550108717419674, 1]
reference:
No comments:
Post a Comment