2017-04-11 70 views
0

爲什麼不是帶有文字「Palim」的標籤可見?設置背景顏色並將小部件置於頂部的好方法是什麼?Kivy背景顏色,小部件不可見

from kivy.app import App 
from kivy.lang import Builder 
from kivy.uix.boxlayout import BoxLayout 
Builder.load_string(""" 
<rootwid>: 
    canvas.before: 
     Color: 
      rgba: [1,1,1,1] 
     Rectangle: 
      pos: self.pos 
      size: self.size 
    Label: 
     text:'Palim'""") 

class rootwid(BoxLayout): 
    pass 

class Testapp(App): 
    def build(self): 
     return rootwid() 

Testapp().run() 

回答

1

它是不可見的,因爲您在白色背景上放置白色標籤。
嘗試使背景灰色:

from kivy.app import App 
from kivy.lang import Builder 
from kivy.uix.boxlayout import BoxLayout 
Builder.load_string(""" 
<rootwid>: 
    canvas.before: 
     Color: 
      rgba: [0.5,0.5,0.5,1] 
     Rectangle: 
      pos: self.pos 
      size: self.size 
    Label: 
     text:'Palim'""") 

class rootwid(BoxLayout): 
    pass 

class Testapp(App): 
    def build(self): 
     return rootwid() 

Testapp().run() 
+1

真的,我沒有想到這一點。 – PalimPalim