【问题标题】:Scrolling custom BoxLayout in kivy Python在 kivy Python 中滚动自定义 BoxLayout
【发布时间】:2020-10-13 12:34:04
【问题描述】:

我创建了自己的 BoxLayout 元素

来自 .kv 文件:

<StageBox>
orientation: 'horizontal'
spacing: 2
BoxLayout:
    id: HoursBox
    size_hint: .045,1
    orientation: 'vertical'
    spacing:1
Cell:
    id: StageCell
    text: ''
    size_hint: .09,1
GridLayout:
    id: GridBox
    spacing: 1
    cols: 30
    rows: 12

在我的主窗口中,我创建了一些 BoxLayout(垂直)来排列我的“StageBox”元素,这些元素将是 6-8 行。它相当多,我真的需要我的根 BoxLayout 可以滚动!

我找不到如何使用带有自定义 BoxLayout 的 ScrollView 或 RecycleView 的信息(在我的例子中)

正如你在图片中看到的那样,我替换了我的 StageBox 的 3 个实例,但正如我所说,我需要一些滚动视图来替换更多实例而不用挤压

【问题讨论】:

    标签: python kivy kivy-language vertical-scrolling


    【解决方案1】:

    我的 main.py 代码

    class StageBox(BoxLayout):
        text = StringProperty()
    
    class MainApp(App):
        stageList = ('item1', 'item2','item3')  #BUT THERE WILL BE MORE
    
        def build(self):
            Window.clearcolor = (.80,.80,.80,1)
            Window.size = (1350, 780)
    
            # HEADER PART  (NON SCROLLABLE)
            TABLE = BoxLayout(orientation = 'vertical', spacing = 4, padding = 10)
            HEADER = BoxLayout(orientation = 'horizontal', size_hint = [1,.08], spacing = 2)
            HEADER.add_widget(Cell(text='HOURS', size_hint = [.045,1]))
            HEADER.add_widget(Cell(text='STAGE', size_hint = [.09,1]))
            DataBox = BoxLayout(orientation = 'vertical', spacing = 2)
            DataBox.add_widget(Cell(text = 'June'.upper()))
            DaysBox = BoxLayout(orientation = 'horizontal', spacing = 1)
            for i in range(1,31):
                DaysBox.add_widget(Cell(text = str(i)))
            DataBox.add_widget(DaysBox)
            HEADER.add_widget(DataBox)
            TABLE.add_widget(HEADER)
    
            # BODY PART  SCROLLABLE !
            scroll = RV()
            BODY = BoxLayout(orientation = 'vertical',spacing = 4)
            for item in self.stageList:
                SB = StageBox()
                Boxy = SB.ids.HoursBox
                for i in range(1,13):
                    Boxy.add_widget(Cell(text=str(i)))
                Grid = SB.ids.GridBox
                for i in range(1,361):
                    Grid.add_widget(Button(text='', background_color = self.whiteColor, background_normal = ''))
                Stage = SB.ids.StageCell
                Stage.text = item
                BODY.add_widget(SB)
    
            TABLE.add_widget(BODY)
            return TABLE
    
    
    if __name__ == "__main__":
        MainApp().run()
    

    【讨论】:

      猜你喜欢
      • 2015-09-30
      • 2019-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      相关资源
      最近更新 更多