From 3677f02403ba828500e1a5ef6579e0f554025c38 Mon Sep 17 00:00:00 2001 From: Alberto Pianon Date: Fri, 13 Dec 2024 11:41:14 +0100 Subject: [PATCH] Fix AttributeError on segmented button created in declarative python In segmentedbutton.kv, we need to check if the MDSegmentButtonIcon object actually has a parent.parent before checking container's parent _label, otherwise you may get the following error: AttributeError: 'NoneType' object has no attribute 'parent' Fix #1735 Signed-off-by: Alberto Pianon --- kivymd/uix/segmentedbutton/segmentedbutton.kv | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kivymd/uix/segmentedbutton/segmentedbutton.kv b/kivymd/uix/segmentedbutton/segmentedbutton.kv index 23ad70e59..fe04e2839 100644 --- a/kivymd/uix/segmentedbutton/segmentedbutton.kv +++ b/kivymd/uix/segmentedbutton/segmentedbutton.kv @@ -52,13 +52,15 @@ "12dp", \ 0, \ 0 \ - if self.parent.parent.ids.container.parent._label else \ + if hasattr(self, "parent") and hasattr(self.parent, "parent") and \ + self.parent.parent.ids.container.parent._label else \ "12dp", \ 0 icon_color: ( \ self.theme_cls.onSecondaryContainerColor \ - if self.parent.parent.ids.container.parent.active else \ + if hasattr(self, "parent") and hasattr(self.parent, "parent") and \ + self.parent.parent.ids.container.parent.active else \ self.theme_cls.onSurfaceColor \ ) \ if self.theme_icon_color == "Primary" else self.icon_color