Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何将多个小部件同时添加到scrollview?_Python 3.x_User Interface_Kivy_Scrollview_Kivy Language - Fatal编程技术网

Python 3.x 如何将多个小部件同时添加到scrollview?

Python 3.x 如何将多个小部件同时添加到scrollview?,python-3.x,user-interface,kivy,scrollview,kivy-language,Python 3.x,User Interface,Kivy,Scrollview,Kivy Language,我是kivy的新手,所以我正在开发一个测试应用程序。我想用ScrollView创建一个屏幕,我想在ScrollView的“行”中添加多个内容,一个文本(描述)和一个图像。 我试过这样做: class PresentUploadedData(Screen): container = ObjectProperty(None) def __init__(self, **kwargs): super(PresentUploadedData, self).__init__

我是kivy的新手,所以我正在开发一个测试应用程序。我想用ScrollView创建一个屏幕,我想在ScrollView的“行”中添加多个内容,一个文本(描述)和一个图像。 我试过这样做:

class PresentUploadedData(Screen):
    container = ObjectProperty(None)

    def __init__(self, **kwargs):
        super(PresentUploadedData, self).__init__(**kwargs)
        Clock.schedule_once(self.setup_scrollview, 1)

    def setup_scrollview(self, dt):
        self.container.bind(minimum_height=self.container.setter('height'))
        self.add_text_inputs()

    def add_text_inputs(self):
        for x in range(30):
            self.container.add_widget(Label(text="Label {}".format(x), size_hint_y=None, height=40, color= [128,0,0,1]))
            self.container.add_widget(Image(source='test.jpg', size_hint=(None, None,), width=50, height=50))
使用此
.kv
文件:

<PresentUploadedData>:
    name: "presentupload"

    message: send
    container: container

    canvas:
        Color:
            rgba: 1,1,1,1
        Rectangle:
            size: self.size
            pos: self.pos

    GridLayout:
        rows: 3
        cols: 1
        spacing: 5
        padding: 5
        font_name: "Calibri"
        background_color: 1,1,1, 1

        ScrollView:
            background_color: 1,1,1, 1
            size_hint: (1, .9)
            bar_width: 10
            bar_color: 128,0,0,0.7
            bar_inactive_color: 128,0,0,1 
            effect_cls: "ScrollEffect"
            scroll_type: ['bars', 'content']
            color: 128,0,0,1

            StackLayout:
                id: container
                size_hint_y: None
                color: 128,0,0,1

            GridLayout:
                cols: 2

        BoxLayout:
            spacing: 5
            size_hint: .7, .1

            Button:
                text: "< BACK"
                id: send
                color: 0, 0, 0, 1
                background_color: .88,.88,.88, 1
                size_hint: .2, 1
                on_release:
                    app.root.current = "main"
                    root.manager.transition.direction = "right"
:
名称:“presentupload”
信息:发送
容器:容器
画布:
颜色:
rgba:1,1,1,1
矩形:
大小:self.size
pos:self.pos
网格布局:
行数:3
科尔斯:1
间距:5
填充:5
字体名称:“Calibri”
背景颜色:1,1,1,1
滚动视图:
背景颜色:1,1,1,1
大小提示:(1.9)
钢筋宽度:10
条形图颜色:128,0,0,0.7
条形图非活动颜色:128,0,0,1
效果:“滚动效果”
滚动类型:['bar','content']
颜色:128,0,0,1
堆栈布局:
id:集装箱
尺寸提示:无
颜色:128,0,0,1
网格布局:
科尔斯:2
盒子布局:
间距:5
大小提示:.7,.1
按钮:
正文:“
但是我有一个
ScrollView只接受一个小部件
异常。

我为什么会得到这个,以及如何解决这个问题?

文件
.kv
中有一个错误:

网格布局:
科尔斯:2
这是没有用的

for
循环中,可以使用另一个
for
解决此问题:

row = [Label(text="Label {}".format(x), size_hint_y=None, height=50, color= [128,0,0,1]), Image(source='test.jpg', size_hint=(None, None,), width=50, height=50)]
            for r in row:
                self.container.add_widget(r)

但是这也没有把东西放在一起,只是让它们放在那里。

.kv
文件中有一个错误:

网格布局:
科尔斯:2
这是没有用的

for
循环中,可以使用另一个
for
解决此问题:

row = [Label(text="Label {}".format(x), size_hint_y=None, height=50, color= [128,0,0,1]), Image(source='test.jpg', size_hint=(None, None,), width=50, height=50)]
            for r in row:
                self.container.add_widget(r)

但是这也没有把东西放在一起,只是让它们放在那里。

是的,
滚动视图只接受一个孩子,所以把这个孩子变成一个
布局
小部件
并在
布局
@JohnAnderson中添加任何你想要的东西。谢谢你的想法,我试着像你说的那样:
布局=BoxLayout(orientation='vertical')布局。添加小部件(Image(source='test.jpg',size\u hint=(无,无),width=50,height=50))布局。添加小部件(Label(text=“Label{}”。format(x),size\u hint\u y=None,height=50,color=[128,0,0,1])self容器。添加小部件(布局)
但这让我在
self.y+self.height/2上出现了
OverflowError
,我的代码中甚至没有这个
。还有
Clock.max\u迭代属性
错误请发布一个。是的,
滚动视图
只接受一个子项,所以将该子项设置为
布局
小部件
,并在
Layout
@JohnAnderson谢谢你的想法,我试着按照你说的那样:
Layout=BoxLayout(orientation='vertical')布局。添加小部件(Image(source='test.jpg',size\u hint=(None,None,),width=50,height=50)布局。添加小部件(Label(text=“Label{}.format(x),size\u hint\u y=None,height=50,color=[128,0,0,1]))self.container.add_widget(layout)
但这让我在
self.y+self.height/2上出现了
overflowerrror
错误,我的代码中甚至没有该错误……还有
Clock.max_迭代属性
错误请发布一个错误。