Scrollview 在 python kivy 应用程序中不起作用

问题描述 投票:0回答:1

我的应用程序中需要如此多的按钮和行,我需要在其他程序中使用滚动条和滚动视图,滚动可以工作,但在这个程序中它不起作用

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView


class Program(App):
    def build(self):

        self.main_layout = BoxLayout(orientation = "vertical")

        self.firstrow = BoxLayout( size_hint_y=None, height=44)
        self.secondrow = BoxLayout( size_hint_y=None, height=44)
        #Actually there are so many rows thats why I need scrollview but I show you brief
        self.grid_izgara=GridLayout( cols=5, spacing=10, padding=10, size_hint_y=None )

        self.scroll_view = ScrollView(size_hint=(None, None), size=(700, 900))
        self.grid_izgara.bind(minimum_height=self.grid_izgara.setter("height"))
        self.eqn = Label(text= "Equation")
        self.equation = TextInput( size_hint_y=None, height=44)

        self.buton = Button(text="Drop Down Menu", size_hint_y=None, height=44)

        self.lowerBound = Label(text="Lower Bound", size_hint_y=None, height=44)
        self.lowerB = TextInput()
        self.upperBound = Label(text="Upper Bound", size_hint_y=None, height=44)
        self.upperB = TextInput()

        self.maxIteration = Label(text="Max Iteration", size_hint_y=None, height=44)
        self.maxI = TextInput()
        self.tolerance = Label(text="Toleration")
        self.toler = TextInput()

        self.solveButon = Button(text="Solve It")

        self.grid_izgara.add_widget(Button(text="bir", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="iki", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="uc", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="dort", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="bes", size_hint_y=None, height=44))

        self.grid_izgara.add_widget(Button(text="birsıfırw", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="ikisıfıwr", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="ucsıfıwr", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="dortsıfıwr", size_hint_y=None, height=44))
        self.grid_izgara.add_widget(Button(text="bessıfırw", size_hint_y=None, height=44))
        # Actually there are so many buttons thats why I need scrollview but I show you brief

        self.firstrow.add_widget(self.eqn)
        self.firstrow.add_widget(self.equation)

        self.secondrow.add_widget(self.solveButon)

        self.main_layout.add_widget(self.firstrow)
        self.main_layout.add_widget(self.buton)
        self.main_layout.add_widget(self.secondrow)

        self.main_layout.add_widget(self.grid_izgara)#Besinci Satırı ekledik
        self.scroll_view.add_widget(self.main_layout)
        return self.scroll_view



Program().run()

我更喜欢仅使用 python 代码来解决这个问题,而无需构建器和 .kv 文件。由于我的知识有限,我无法轻松处理它们。

python user-interface kivy scrollview scrollbar
1个回答
0
投票

您需要将

minimum_height
用于
main_layout
,就像您对
grid_izgara
所做的那样。像这样:

    self.main_layout = BoxLayout(orientation = "vertical", size_hint_y=None)
    self.main_layout.bind(minimum_height=self.main_layout.setter('height'))
© www.soinside.com 2019 - 2024. All rights reserved.