Dynamically changing the background color for a widget added to a gridlayout

Morning….

Having a bit of trouble with a custom widget added to a column of a kivy gridlayout. I still learning kivy/kivyMD and was able to previously do this quite easily with PYQT6.

When my main page opens I’m reading a SQLite Database and loading the record contents in a gridlayout. I know you achieve this by setting the background properties for each widget added but in my case my custom widget has Buttonbehavior and an Image widget which I’m using to display and clickable image within the gridlayout. I read a posting saying you can set the background by setting the background_normal to “” and background_color to a color list but this did not work for me. I tried dynamically setting the canvas.before and canvas.after while loading the record contents but this as well messed up my screen.

What’s currently happening is the image does properly display in my gridlayout but the background color is not working. The background color for the odd row setting was originally a color list of [.78, .85, .92, 1] which also did not work.

As usual any suggestions greatly appreciated.

thanks

main.py: (bottom function after page is displayed)

def show_service_schedule(self):

# Read Service Schedule

self.schedule_recs = DataRtns.get_records("schedule")

if len(self.schedule_recs) > 0:

    self.ids.scrollgrid.rows = len(self.schedule_recs)

    # Adjust Scrollview height if rows are less than 5

    if self.ids.scrollgrid.rows < 5:

        # Adjust Title padding as well

        if self.ids.scrollgrid.rows == 1:
            self.ids.title.padding = [0, 0, 0, dp(90)]
        else:
            dp_val = self.ids.scrollgrid.row_default_height * self.ids.scrollgrid.rows + 60
            self.ids.title.padding = [0, 0, 0, dp(dp_val)]

        self.ids.scroll.height = self.ids.scrollgrid.row_default_height * self.ids.scrollgrid.rows

    recCtr = 0

    for rec in self.schedule_recs:

        if recCtr % 2 > 0:

            addr_col = ClickLabel()
            addr_col.text = rec[2]
            addr_col.padding = [5, 0]
            addr_col.md_bg_color = "#c5d8ea"

            city_col = ClickLabel()
            city_col.text = rec[3]
            city_col.padding = [40, 0]
            city_col.md_bg_color = "#c5d8ea"

            type_col = ClickLabel()
            type_col.text = rec[4]
            type_col.padding = [20, 0]
            type_col.md_bg_color = "#c5d8ea"

            stat_col = StatButton()
            stat_col.background_normal = ""
            stat_col.background_color = "#c5d8ea"
            stat_col.source = self.get_image(rec[4], rec[6])

        else:

            addr_col = ClickLabel(text=rec[2], padding=[5, 0])
            city_col = ClickLabel(text=rec[3], padding=[40, 0])
            type_col = ClickLabel(text=rec[4], padding=[20, 0])

            stat_col = StatButton()
            stat_col.background_normal = ""
            stat_col.background_color = [.9, .9, .9, 1]
            stat_col.source = self.get_image(rec[4], rec[6])


        self.ids.scrollgrid.add_widget(addr_col)
        self.ids.scrollgrid.add_widget(city_col)
        self.ids.scrollgrid.add_widget(type_col)
        self.ids.scrollgrid.add_widget(stat_col)

        recCtr += 1

else:

    self.ids.title.padding = [0, 0, 0, dp(90)]

    self.ids.scrollgrid.cols = 1
    self.ids.scrollgrid.rows = 1
    self.ids.scroll.height = dp(36)

    self.schedule_recs = []

    no_records_col = MDLabel(text="- No Records Exist -", halign="center")
    self.ids.scrollgrid.add_widget(no_records_col)

custom widget:

class StatButton(ButtonBehavior, Image):
    def on_release(self):
        print("Image clicked ...")

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật