Python 在Recycleview Kivy中显示不同的小部件类型

Python 在Recycleview Kivy中显示不同的小部件类型,python,kivy,Python,Kivy,我想知道是否有可能在kivy recycleview中显示不同的小部件类型,我让它显示文本框,这很好,但是否有可能在同一个循环视图中显示图像,或者我是否必须在现有的循环视图上创建另一个循环视图,这是我的代码和当前的应用程序快照,我目前的理解是,在recycle view mine中只能有一个viewclass是文本输入,因此如何将另一个视图类添加到同一个recycle view中 当前屏幕 主电压(千伏) SelectableReportTextbox: size_hint

我想知道是否有可能在kivy recycleview中显示不同的小部件类型,我让它显示文本框,这很好,但是否有可能在同一个循环视图中显示图像,或者我是否必须在现有的循环视图上创建另一个循环视图,这是我的代码和当前的应用程序快照,我目前的理解是,在recycle view mine中只能有一个viewclass是文本输入,因此如何将另一个视图类添加到同一个recycle view中

当前屏幕

主电压(千伏)

   SelectableReportTextbox:



    size_hint:  None,None
    text_size : self.text_size
    size_hint_y: None
    font_size: self.height*0.2
    foreground_color: [1, 1, 1, 1]
    readonly: True
    background_color: (0.1, 0.3, 0.7, 0.7)
    padding_x: [30,30]
    font_name: 'C:\kivy_venv\Graphics\GIL_____.TTF'
    border: [50,50,50,50]







  ScreenTwo:
  




    canvas.before:


            Rectangle:
                    size:self.size           #100, 100
                    pos: self.pos
                    source: "C:\kivy_venv\Graphics\Jetfire back.png"


    RecycleView:

            do_scroll: True, True
            bar_width: 6
            size_hint: (None, None)
            id: scrlv
            size: (500, 500)
            pos_hint: {'center_x': .75, 'center_y': .64}
            scroll_y: 0
            multiline:True




            ProjectRV:

                    viewclass: 'SelectableReportTextbox'        # defines the viewtype for the data items.
                    orientation: "vertical"
                    scroll_type: ['bars', 'content']
                    scroll_wheel_distance: dp(114)
                    key_size: "height"

                    padding:1, 1
                    space_x: self.size[0]/3
                    id: rv
                    pos_hint: {'center_x': 0.32, 'center_y': 0.525}
                    bar_width: dp(25)
                    bar_color: (0.7, 0.1, 0.3, 0.7)
                    bar_inactive_color: (0.1, 0.1, 0.1 , 1)
                    scroll_y : 0





                    SelectableRecycleBoxLayout:


                            data : []
                            spacing : '5'
                            default_size_hint: 1, None
                            size_hint_y: None
                            height: self.minimum_height
                            multiselect: True
                            touch_multiselect: True
                            orientation: 'vertical'




                            SelectableRecycleBoxLayout:

                                    data : []
                                    color:(0, 0.7, 0.4, 0.4)
                                    spacing : '5'
                                    default_size_hint: 1, None
                                    size_hint_y: None
                                    height: self.minimum_height
                                    multiselect: True
                                    touch_multiselect: True
                                    orientation: 'vertical'

您可以定义自己的
viewclass
,以显示所需内容。您的
viewclass
必须具有与
RecycleView
数据中的键对应的
属性

下面是一个简单的例子:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView


class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)

        # set up the data
        self.data = [
            {'text': 'Some Text', 'image': 'dots.png'},
            {'text': 'more text', 'image': 'tester.png'}
            ]

kv = '''
<MyViewClass@BoxLayout>:
    # define the properties that appear in the data
    text: ''
    image: ''
    
    # define how the data is displayed
    Image:
        source: root.image
    Label:
        text: root.text
RV:
    viewclass: 'MyViewClass'
    RecycleBoxLayout:
        padding: 10, 0, 10, 0
        size_hint_y: None
        height: self.minimum_height
        default_size: None, 40
        default_size_hint: 1, None
        orientation: 'vertical'
        spacing: 3
'''

class TestApp(App):
    def build(self):
        return Builder.load_string(kv)

TestApp().run()
从kivy.app导入应用
从kivy.lang导入生成器
从kivy.uix.recycleview导入recycleview
RV级(回收利用审查):
定义初始(自我,**kwargs):
超级(RV,自我)。\uuuuu初始值(**kwargs)
#设置数据
self.data=[
{'text':'Some text','image':'dots.png'},
{'text':'moretext','image':'tester.png'}
]
kv='''
:
#定义数据中显示的属性
文本:“”
图像:“”
#定义数据的显示方式
图片:
来源:root.image
标签:
text:root.text
房车:
viewclass:“MyViewClass”
循环利用布局:
填充:10,0,10,0
尺寸提示:无
高度:自身最小高度
默认大小:无,40
默认大小提示:1,无
方向:“垂直”
间距:3
'''
类TestApp(应用程序):
def生成(自):
返回生成器。加载字符串(kv)
TestApp().run()

您可以定义自己的
viewclass
来显示您想要的任何内容。您的
viewclass
必须具有与
RecycleView
数据中的键对应的
属性

下面是一个简单的例子:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.recycleview import RecycleView


class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)

        # set up the data
        self.data = [
            {'text': 'Some Text', 'image': 'dots.png'},
            {'text': 'more text', 'image': 'tester.png'}
            ]

kv = '''
<MyViewClass@BoxLayout>:
    # define the properties that appear in the data
    text: ''
    image: ''
    
    # define how the data is displayed
    Image:
        source: root.image
    Label:
        text: root.text
RV:
    viewclass: 'MyViewClass'
    RecycleBoxLayout:
        padding: 10, 0, 10, 0
        size_hint_y: None
        height: self.minimum_height
        default_size: None, 40
        default_size_hint: 1, None
        orientation: 'vertical'
        spacing: 3
'''

class TestApp(App):
    def build(self):
        return Builder.load_string(kv)

TestApp().run()
从kivy.app导入应用
从kivy.lang导入生成器
从kivy.uix.recycleview导入recycleview
RV级(回收利用审查):
定义初始(自我,**kwargs):
超级(RV,自我)。\uuuuu初始值(**kwargs)
#设置数据
self.data=[
{'text':'Some text','image':'dots.png'},
{'text':'moretext','image':'tester.png'}
]
kv='''
:
#定义数据中显示的属性
文本:“”
图像:“”
#定义数据的显示方式
图片:
来源:root.image
标签:
text:root.text
房车:
viewclass:“MyViewClass”
循环利用布局:
填充:10,0,10,0
尺寸提示:无
高度:自身最小高度
默认大小:无,40
默认大小提示:1,无
方向:“垂直”
间距:3
'''
类TestApp(应用程序):
def生成(自):
返回生成器。加载字符串(kv)
TestApp().run()

谢谢约翰,你总是那么乐于助人,你的榜样是格雷特·汉克斯·约翰,你总是那么乐于助人,你的榜样太棒了