2017-12-08 3 views
0

ScrollViewウィジェットが2つあり、それぞれのScroll_yを同期したい場合。 私のコードでは、Scroll_Aでスクロールしても、それ自体は動かず、Scroll_Bはリアルタイムで動かない。 Scroll_yとこれらの2つのScrollViewをリアルタイムで同期させるには、どのようなコードを書くべきですか?kivy each Scroll_y

python 
from kivy.app   import App 
from kivy.lang   import Builder 
from kivy.uix.scrollview import ScrollView 
from kivy.properties  import ObjectProperty 

class Scroll_A(ScrollView): 
    scroll_b = ObjectProperty(None) 
    def on_scroll_move(self, touch): 
     self.scroll_b.scroll_y = self.scroll_y 

class Scroll_B(ScrollView): 
    def on_scroll_move(self, touch): 
     pass 

Mykv = ''' 
GridLayout: 
    cols: 2 
    spacing: 100, 100 
    padding: 50, 50, 50, 50 
    Scroll_A: 
     id: scroll_a 
     scroll_b: scroll_b 
     do_scroll_y: True 
     pos_hint: {'top': 1} 
     Label: 
      size_hint_y: None 
      text_size: self.width, None 
      color: 1,1,1,1 
      height: self.texture_size[1] 
      text: 'X' * 1000 
    Scroll_B: 
     id: scroll_b 
     do_scroll_y: True 
     pos_hint: {'top': 1} 
     Label: 
      size_hint_y: None 
      text_size: self.width, None 
      color: 1,1,1,1 
      height: self.texture_size[1] 
      text: 'Y' * 1000 
''' 

class MyApp(App): 

    def build(self): 
     return Builder.load_string(Mykv) 

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

答えて

0

私の問題を解決しました。

#python 
from kivy.app   import App 
from kivy.lang   import Builder 
from kivy.uix.scrollview import ScrollView 
from kivy.properties  import ObjectProperty 

class Scroll_A(ScrollView): 
    scroll_b = ObjectProperty(None) 
    pass 

class Scroll_B(ScrollView): 
    pass 

Mykv = ''' 
GridLayout: 
    cols: 2 
    spacing: 100, 100 
    padding: 50, 50, 50, 50 
    Scroll_A: 
     id: scroll_a 
     scroll_b: scroll_b 
     do_scroll_y: False 
     scroll_y: self.scroll_b.scroll_y 
     pos_hint: {'top': 1} 
     Label: 
      size_hint_y: None 
      text_size: self.width, None 
      color: 1,1,1,1 
      height: self.texture_size[1] 
      text: 'X' * 10000 
    Scroll_B: 
     id: scroll_b 
     do_scroll_y: True 
     pos_hint: {'top': 1} 
     Label: 
      size_hint_y: None 
      text_size: self.width, None 
      color: 1,1,1,1 
      height: self.texture_size[1] 
      text: 'Y' * 10000 
''' 

class MyApp(App): 

    def build(self): 
     return Builder.load_string(Mykv) 

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