SHARE
TWEET

Untitled

a guest Jul 19th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ForeignLanguage = ColoredLabel(..., size = (a,b))
  2.      
  3. from kivy.app import App
  4.     from kivy.uix.boxlayout import BoxLayout
  5.     from kivy.uix.label import Label
  6.     from kivy.properties import ListProperty
  7.     from kivy.lang import Builder
  8.     from kivy.core.window import Window
  9.  
  10.  
  11.     kv = '''
  12.     <ColoredLabel>:
  13.         size: (self.size_x,self.size_y)
  14.         pos: (0,0) # no effect
  15.         background_color:
  16.         canvas.before:
  17.             Color:
  18.                 rgba: self.background_color
  19.             Rectangle:
  20.                 pos: self.pos
  21.                 size: (self.size_x,self.size_y)
  22.         '''
  23.  
  24.     Builder.load_string(kv)
  25.  
  26.     class ColoredLabel(Label):
  27.         background_color = ListProperty((0,0,0,1))
  28.         s_global = Window.size
  29.         size_x = s_global[0]
  30.         size_y = s_global[1]/3
  31.  
  32.     class MyWidget(BoxLayout):
  33.         #init
  34.         def __init__(self, **kwargs):
  35.             super().__init__(**kwargs)
  36.             ForeignLanguage = ColoredLabel(text="ForeignLanguage", size_hint=(None, None), background_color=(0/255,171/255,169/255, 1))
  37.             Translation = ColoredLabel(text="Translation", size_hint=(None, None), background_color=(45/255,137/255,239/255, 1))
  38.             Example = ColoredLabel(text="Example", size_hint=(None, None), background_color=(43/255,87/255,151/255, 1))
  39.             verticalBox     = BoxLayout(orientation='vertical')
  40.             verticalBox.add_widget(ForeignLanguage)
  41.             verticalBox.add_widget(Translation)
  42.             verticalBox.add_widget(Example)
  43.             self.add_widget(verticalBox)
  44.  
  45.     class BoxLayoutDemo(App):
  46.         def build(self):
  47.             return MyWidget()
  48.  
  49.     if __name__ == '__main__':
  50.         BoxLayoutDemo().run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top