2017-11-06 8 views
0

1つのルートルールセットで1つのスクリーンアプリを作成しようとしています。ボタンを押すと、ボタンの横のグリッドにスクロール可能なテキストが表示されます。すべてのサンプルソリューションで、私はscrollviewが他の質問で見たのと同じようなKVファイルで作業しているのを見ています。誰かが私がKVファイルで逃したものを特定してください。ラベル上のグリッドレイアウト内のkivyスクロールビュー

私の.pyファイル:

import kivy 
import string 
from kivy.app import App 
from kivy.uix.widget import Widget 
from kivy.uix.label import Label 
from kivy.uix.button import Button 
from kivy.uix.boxlayout import BoxLayout 
from kivy.uix.gridlayout import GridLayout 
from kivy.properties import ObjectProperty 
from kivy.properties import StringProperty 
from kivy.uix.scrollview import ScrollView 
from kivy.core.window import Window 

class RootContainer(BoxLayout): 
    instance = ObjectProperty(None) 

    def __init__(self, **kwargs): 
     super(RootContainer, self).__init__(**kwargs) 

    def clickAction1(self, instance): 
     #identify the button pressed 
     buttonText = instance.text 
     self.lbl1.text = instance.text + " some text goes here ... " 
     myresult = " this is scrolling text.\n " * 30 
     self.lbl5.text = myresult 

class MBApp(App): 
    def build(self): 
     return RootContainer() 


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

私のKVファイル:

#:kivy 1.0.9 
<RootContainer>: 
    id: theRoot 
    lbl1: my_labelC 
    lbl5: my_labelCS 
BoxLayout: 
    orientation: 'vertical' 
    spacing: 20 
    padding: 20 
    canvas: 
     Color: 
      rgb: 0, .33, 0 
     Rectangle: 
      pos: self.pos 
      size: self.size 
    Button: 
     text: "This is 1st button" 
     text_size: self.size 
     size_hint: (.5,1) 
     on_press: theRoot.clickAction1(self) 
    Button: 
     text: "This is 2nd button" 
     text_size: self.size 
     size_hint: (.5,1) 
     on_press: root.clickAction1(self) 

GridLayout: 
    rows: 2 
    cols: 1 
    spacing: 10 
    padding: 10 
    canvas: 
     Color: 
      rgb: .7, .63, 0 
     Rectangle: 
      pos: self.pos 
      size: self.size 
    Label: 
     id: my_labelC 
     canvas.before: 
      Color: 
       rgb: 0,0,0 
      Rectangle: 
       pos: self.pos 
       size: self.size 
     text: "Header text for button clicked ......." 
     text_size: self.size 
    ScrollView: 
     GridLayout: 
      cols:1 
      rows:1 
      height: self.minimum_height 
      Label: 
       id: my_labelCS 
       text: "Scrolling text goes here ....." 

私はこれが重複ではありません願っています。その他のコードの提案も歓迎します。ありがとうございました。

答えて

1

あなたのラベルのサイズを設定していないので、デフォルトではすべてのウィジェットとして、デフォルトでは親

size: 100, 100 
size_hint: 1, 1 

size_hint以降は1, 1であり、かつ、適用されます。これが私の作品あなたが親レイアウトにsize: minimum_sizeを設定しているので、size自体が親の空き容量で上書きされます

子供が必要とする最小サイズを与えますが、ラベルはスペースを要求しません。size_hint1, 1であることは、利用可能なスペースをすべて利用できることを意味します。 Kivyはスペースを与えないことでこの状況を解決するので、Labelのサイズは0, 0になり、GridLayoutのサイズも同じになります。

ですから、ラベル、少なくとも高さ(size_hintを無効にし、代わりに通常利用できる幅にテクスチャの幅を設定するに味方されたテクスチャの高さ

size_hint_y: None 
height: self.texture_size[1] 

に設定したいです、 text_sizeを設定することもできます。

text_size: self.width, None 
size_hint_x: 1 # this is the default, so this line is not required, but you want to be sure not to disable this default 
+0

上のコメントは、それは親と子の大きさがどのように相互作用するかの私の理解を明らかにした。Tshirtman。偉大な説明ありがとうございます。 – kmtomile

+0

は、受け入れられたとして、あなたは答えをマークすることができます!ありがとう? :) – Tshirtman

-1

本当にあなたのスクロールビュー内にGridLayoutが必要ですか?

ScrollView: 
    Label: 
     id: my_labelCS 
     size_hint: 1, None 
     text_size: self.width, None 
     height: self.texture_size[1] 
     text: "Scrolling text goes here ....." 
+0

ジョン、感謝コード。 – kmtomile

関連する問題