2014-10-11 48 views
0

Sc.kv按鈕沒有調整到適合文本(Kivy)

<Selector>: 
    pos: 200, 400 

<ScLayout>: 
    cols: 2 
    pos: self.parent.pos 
    spacing: 10 

<Button>: 
    width: len(self.text) * 50 

FloatLayout: 
    Selector: 
     ScLayout: 
      Button: 
       text: 'hey' 
      Button: 
       text: 'welcome' 
      Button: 
       text: 'hi' 
      Button: 
       text: 'how are you' 

和ScApp.py

from kivy.app import App 
from kivy.uix.widget import Widget 
from kivy.uix.gridlayout import GridLayout 
from kivy.uix.button import Button 

class Selector(Widget): pass 

class ScLayout(GridLayout): pass 

class ScApp(App): 

    def build(self): 
     pass 

if __name__ == '__main__': 
    ScApp().run() 

我想要的按鈕來調整大小以適合文本的大小,但是什麼代之以: (not enough rep to embed images!)

爲什麼會發生這種情況?以及我該如何解決這個問題?

回答

1

我寫了一個blog post涵蓋此等事情。關鍵是綁定Button大小以跟蹤其紋理大小。

+0

如果我做了'

相關問題