不存在的线

发布于 2025-02-09 05:33:08 字数 1918 浏览 2 评论 0原文

我正在学习Kivy,并且正在MDExpansionpanel小部件上。 来自JSON的数据源我使用键组装我的面板和值来构成我的内容。

碰巧我能够做到这一点,但是我的内容中总是会出现一条额外的行。

我希望您的帮助删除这一行。

我将在下面发布我的代码:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty, ObjectProperty


json_data = {'01001BA476': {'price': '74.73',
                            'product_code': '000003',
                            'quantity': '100'},
             '0100251633': {'price': '92.07',
                            'product_code': '000156',
                            'quantity': '1000'}}


KV = '''
<ClassDetails>
    orientation: 'vertical'
    adaptive_height: True
    OneLineIconListItem:
        id: info_line
        text: root.text
        on_press: root.action()

        IconLeftWidget:
            icon: 'star'
            on_press: print(f'star pressed on line: {info_line.text}')

ScrollView:
    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class ClassDetails(MDBoxLayout):
    text = StringProperty()
    action = ObjectProperty()

class InvoicePanel(MDExpansionPanel):
    pass

class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def fechar_pedido(self):
        print('You clicked on the information line')

    def on_start(self):
        for class_title, class_details in json_data.items():
            cd = ClassDetails()
            expansion_panel = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {class_title}'), content=cd)
            self.root.ids.box.add_widget(expansion_panel)

            for item in class_details.items():
                cd.add_widget(ClassDetails(
                    text=str(class_details.values()), action=self.fechar_pedido))

Test().run()

I'm learning Kivy and I'm on the MDExpansionPanel widget.
Data source from a JSON I use the keys to assemble my panels and the values to compose my Contents.

It happens that I'm able to do it but an extra line always appears in my contents.

I would like your help to delete this line.

I will post my code below:

from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelOneLine
from kivy.properties import StringProperty, ObjectProperty


json_data = {'01001BA476': {'price': '74.73',
                            'product_code': '000003',
                            'quantity': '100'},
             '0100251633': {'price': '92.07',
                            'product_code': '000156',
                            'quantity': '1000'}}


KV = '''
<ClassDetails>
    orientation: 'vertical'
    adaptive_height: True
    OneLineIconListItem:
        id: info_line
        text: root.text
        on_press: root.action()

        IconLeftWidget:
            icon: 'star'
            on_press: print(f'star pressed on line: {info_line.text}')

ScrollView:
    MDGridLayout:
        id: box
        cols: 1
        adaptive_height: True
'''


class ClassDetails(MDBoxLayout):
    text = StringProperty()
    action = ObjectProperty()

class InvoicePanel(MDExpansionPanel):
    pass

class Test(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def fechar_pedido(self):
        print('You clicked on the information line')

    def on_start(self):
        for class_title, class_details in json_data.items():
            cd = ClassDetails()
            expansion_panel = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {class_title}'), content=cd)
            self.root.ids.box.add_widget(expansion_panel)

            for item in class_details.items():
                cd.add_widget(ClassDetails(
                    text=str(class_details.values()), action=self.fechar_pedido))

Test().run()

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

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

发布评论

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

评论(1

夜声 2025-02-16 05:33:08

我认为,将您的初始content设置为classDetails实例,该额外的线条来自其定义中具有onelineiconListItem。尝试用简单的mdboxlayout而替换content

def on_start(self):
    for class_title, class_details in json_data.items():
        print(class_title, class_details)
        # cd = ClassDetails()
        cd = MDBoxLayout(orientation='vertical', adaptive_height=True)
        expansion_panel = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {class_title}'), content=cd)
        self.root.ids.box.add_widget(expansion_panel)

        for item in class_details.items():
            print('\titem:', item)
            cd.add_widget(ClassDetails(
                text=str(class_details.values()), action=self.fechar_pedido))

I think the extra line is coming from setting your initial content to a ClassDetails instance, which has a OneLineIconListItem in its definition. Try replacing the content with a simple MDBoxLayout instead:

def on_start(self):
    for class_title, class_details in json_data.items():
        print(class_title, class_details)
        # cd = ClassDetails()
        cd = MDBoxLayout(orientation='vertical', adaptive_height=True)
        expansion_panel = InvoicePanel(panel_cls=MDExpansionPanelOneLine(text=f'Invoice #: {class_title}'), content=cd)
        self.root.ids.box.add_widget(expansion_panel)

        for item in class_details.items():
            print('\titem:', item)
            cd.add_widget(ClassDetails(
                text=str(class_details.values()), action=self.fechar_pedido))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文