KivyMD-right/left_action_items导致“弱引用对象不再存在"; [英] KivyMD - right/left_action_items causes "weakly-referenced object no longer exists"

查看:112
本文介绍了KivyMD-right/left_action_items导致“弱引用对象不再存在";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习KivyMD,并决定编写一个简单的购物清单应用程序.

I'm trying to learn KivyMD and decided to write a simple shopping list app.

我想通过对话框窗口将新条目添加到购物清单中.尝试运行以下代码时出现错误:

I want to add new entries to the shopping list by adding them via dialog window. I am getting an error when trying to run the below code:

from kivymd.app import MDApp
from kivymd.uix.list import MDList, IconLeftWidget, OneLineIconListItem
from kivymd.icon_definitions import md_icons
from kivymd.uix.toolbar import MDToolbar
from kivymd.uix.dialog import MDDialog
from kivy.properties import ObjectProperty
from kivymd.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivymd.uix.screen import Screen
from kivymd.uix.button import MDFlatButton
from kivymd.uix.textfield import MDTextFieldRect, MDTextField


class ShoppingListApp(MDApp):

    def build(self):
        screen = Screen()
        scroll = ScrollView()
        toolbar = MDToolbar(title="Shopping List", anchor_title="center")
        toolbar.right_action_items = [['plus', self.dialog_window]]
        screen.add_widget(scroll)
        self.kvmd_list = MDList()
        #self.test_button = MDFlatButton(text="TEST BUTTON", on_press=self.dialog_window)
        #screen.add_widget(self.test_button)
        scroll.add_widget(self.kvmd_list)
        self.theme_cls.theme_style = "Light"
        self.theme_cls.primary_palette = "BlueGray"
        self.theme_cls.primary_hue = '400'
        self.kvmd_list.add_widget(toolbar)

        return screen

    def dialog_window(self, obj):
        self.dialog = MDDialog(
            title="Add new item:",
            buttons=[
                MDFlatButton(
                    text="Add",
                ),
            ],

        )
        self.dialog.set_normal_height()
        self.dialog.open()


ShoppingListApp().run()

我得到的错误是:

弱引用对象不再存在

weakly-referenced object no longer exists

我将其范围缩小到toolbar.right_action_items = [['plus', self.dialog_window]],很难确定是左还是右.

I narrowed it down to toolbar.right_action_items = [['plus', self.dialog_window]], tough it doesn't matter if it's left or right.

当我取消注释self.test.button时,问题消失了.

The issue disappears when I uncomment the self.test.button.

我不明白为什么会这样.我在这里真的缺少一些基本的东西吗?

I fail to understand why this happens. Am I missing something really basic here?

谢谢.

推荐答案

使用Kivy kivy 2.0.0rc3版本.

Use Kivy kivy 2.0.0rc3 version.

这篇关于KivyMD-right/left_action_items导致“弱引用对象不再存在";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆