缺少回收视图小部件

发布于 2025-01-09 05:41:35 字数 1624 浏览 0 评论 0原文

我需要创建一个自动填充应用程序,顶部有标签和文本输入,底部有回收视图。但是,当我运行该程序时,即使我已在字符串中设置,回收视图也会消失。该应用程序将通过在文本输入中键入名称来方便搜索内容,相关内容将出现在回收视图中,因此用户无需查看长长的内容列表。

from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.recycleview import RecycleView
from kivy.uix.boxlayout import BoxLayout

Window.size = (350, 600)

Builder.load_string('''
<MyLayout>:
    BoxLayout:
        orientation: "vertical"
        spacing: 10
        padding: 10

        Label :
            text : 'Favourite Pizza'
           
        TextInput :
            font_size: 30
            focus: True
            multiline : False
           
        <RV>:    
            RecycleBoxLayout:   
                viewclass: 'TextInput'        
                default_size: None, 30
                default_size_hint: 1, None
                size_hint_y: .8
                height: self.minimum_height
                orientation : 'vertical'  
                  
''')

class MyLayout(BoxLayout):
    pass

class RV(RecycleView):  
    def __init__(self, **kwrgs):
        super(RV, self).__init__(**kwrgs)
        content = ["Pepperoni", "Cheese","Papper", "Hawaii", "Seafood", 
        "Ham", "Taco", "Onion"]
        self.data = [{'text':item} for item in content]     
        print(content)

class MainApp(App):
    title='Search App'
    def build(self):
        Window.clearcolor = (51/255, 153/255, 1, 1) 
        return MyLayout()    
   
MainApp().run()

我应该怎么做才能获得完整的视图(标签、文本输入和回收视图)?我想输入一个输入文本,相关内容会出现在回收视图中,我可以使用回收视图来达到这个目的吗?我可以同时使用 BoxLayout 和 RecycleBoxLayout 吗,因为它引用了不同的小部件?

I need to create an autofill app, I have a label and text input on the top, and recycle view on the bottom. However, when I run the program, the recycle view disappears, even though I have set in the string. This app will facilitate searching content by typing the name in the text input and the relevant content will appear in the recycle view, so the user is not required to view through the long list of content.

from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.recycleview import RecycleView
from kivy.uix.boxlayout import BoxLayout

Window.size = (350, 600)

Builder.load_string('''
<MyLayout>:
    BoxLayout:
        orientation: "vertical"
        spacing: 10
        padding: 10

        Label :
            text : 'Favourite Pizza'
           
        TextInput :
            font_size: 30
            focus: True
            multiline : False
           
        <RV>:    
            RecycleBoxLayout:   
                viewclass: 'TextInput'        
                default_size: None, 30
                default_size_hint: 1, None
                size_hint_y: .8
                height: self.minimum_height
                orientation : 'vertical'  
                  
''')

class MyLayout(BoxLayout):
    pass

class RV(RecycleView):  
    def __init__(self, **kwrgs):
        super(RV, self).__init__(**kwrgs)
        content = ["Pepperoni", "Cheese","Papper", "Hawaii", "Seafood", 
        "Ham", "Taco", "Onion"]
        self.data = [{'text':item} for item in content]     
        print(content)

class MainApp(App):
    title='Search App'
    def build(self):
        Window.clearcolor = (51/255, 153/255, 1, 1) 
        return MyLayout()    
   
MainApp().run()

What should I do in order to get a complete view (label, text input & recycle view)? I want to type an input text, the relevant content will appear in the recycle view, can I use recycle view to achieve this purpose? Can I use both BoxLayout and the RecycleBoxLayout at the same time, since it refers to the different widgets?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2025-01-16 05:41:35

首先,动态类必须与root处于同一级别。

其次,为了让RecycleView垂直增长,这里,你必须将RecycleBoxLayoutsize_hint_y设置为None。因此,您的 kvlang 现在应该如下所示:

<MyLayout>:
    BoxLayout:
        orientation: "vertical"
        spacing: 10
        padding: 10

        Label :
            text : 'Favourite Pizza'
           
        TextInput :
            font_size: 30
            focus: True
            multiline : False
           
        RV:


<RV>:
    viewclass: 'TextInput'
    RecycleBoxLayout:
        default_size: None, 30
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation : 'vertical'

First of all, dynamic classes must be in the same level as root.

Secondly in order to make RecycleView grow vertically, here, you have to set size_hint_y of RecycleBoxLayout to None. Thus your kvlang should now look like,

<MyLayout>:
    BoxLayout:
        orientation: "vertical"
        spacing: 10
        padding: 10

        Label :
            text : 'Favourite Pizza'
           
        TextInput :
            font_size: 30
            focus: True
            multiline : False
           
        RV:


<RV>:
    viewclass: 'TextInput'
    RecycleBoxLayout:
        default_size: None, 30
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation : 'vertical'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文