2016-08-26 6 views
2

Я ищу, чтобы сделать страницу в Python с использованием библиотеки Kivy следующего форматаКак сделать часть экрана Kivy прокруткой

________________________ 
    |      | 
    |  title   | 
    |______________________| 
    >>|  Example 1  |<< 
    |______________________| 
    |   |   | 
    |___________|__________| 
    |   |   | 
    |___________|__________| 
    |   |   | 
    >>|___________|__________|<< 
    |   Home   | 
    |______________________| 
    |  Settings  | 
    |______________________|   

Часть экрана между стрелками должны быть прокручивать. Код у меня есть для этого до сих пор выглядит следующим образом:

Kv Файл:

<ExampleScreen>: 
BoxLayout: 
    orientation: 'vertical' 
    Label: 
     text: 'title' 
    ScrollView: 
     GridLayout: 
      cols: 1 
      Label: 
       text: 'Example 1' 
      GridLayout: 
       cols: 2 
       rows: 4 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
       Label: 
        text: 'Filler' 
    Button: 
     text: 'Home' 
     size_hint: 1, .1 
     on_press: root.manager.current = 'home' 
    Button: 
     text: 'Settings' 
     size_hint: 1, .1 
     on_press: root.manager.current = 'settings' 

Py файл:

from kivy.uix.gridlayout import GridLayout 
from kivy.uix.scrollview import ScrollView 
from kivy.app import App 
from kivy.uix.screenmanager import ScreenManager, Screen 
from kivy.uix.button import Button 
from kivy.lang import Builder 

Builder.load_file('example.kv') 

class ExampleScreen(Screen): 
    pass 

sm = ScreenManager() 

sm.add_widget(ExampleScreen(name = 'example')) 

class TestApp(App): 
    def build(self): 
     return sm 

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

Я попытался реализации это несколькими способами, и ничего не работает. Кто-нибудь еще имеет опыт работы с этим/знает, возможно ли это? Спасибо за вашу помощь!

ответ

1

Да, возможно, если вы получите подсказки в виде отступа и размера.
ScrollView doc

Попробуйте это:

<[email protected]>: 
    size_hint:1,None 

<ExampleScreen>: 
    BoxLayout: 
     orientation: 'vertical' 
     Label: 
      text: 'title' 
     ScrollView: 
      size_hint: 1,None 
      GridLayout: 
       size_hint: 1,None 
       height: self.minimum_height 
       cols: 1 
       MyLabel: 
        text: 'Example 1' 
       GridLayout: 
        size_hint: 1,None 
        height: self.minimum_height 
        cols: 2 
        rows: 4     
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 
        MyLabel: 
         text: 'Filler' 

     Button: 
      text: 'Home' 
      size_hint: 1, .1 
      on_press: root.manager.current = 'home' 
     Button: 
      text: 'Settings' 
      size_hint: 1, .1 
      on_press: root.manager.current = 'settings' 
Смежные вопросы