Search code examples
kivykivymd

Kivy Image Sizing Problem: Image Can't fill the Boxlayout


i have a guide part in my app and there is a GridLayout so i sent it some labels there is no problem but i need to show a screenshot there, so first i created a class Result(ButtonBehavior, Image): and added this to box_resim = BoxLayout(size_hint_y = None, height = dp(326)) Lastly i added it to box3 = GuideBoxLayout() . I want screenshot to full/fill the boxlayout but could not do that.

By the way Image size 955x326

KV File Parts

<GuideBoxLayout>:
    size_hint_y: None
    orientation: 'vertical'
    padding: '20dp', 0, '20dp', 0
    height: self.minimum_height
    background_color: 0.678, 0.129, 0.459, 1               
    canvas.before: 
        Color:
            rgba: self.background_color
        RoundedRectangle:
            size: self.size
            pos: self.pos
            radius: [10, 10, 10, 10] 

and

BoxLayout:
    size_hint: 1, 0.70
    padding: '20dp', 0, '20dp', 0  
    ScrollView:
        id: sv_guide_tr
        scroll_timeout: 100000
        scroll_type: ['bars', 'content']
        bar_margin: '-5dp'
        bar_color: 1, 1, 1, 1
        bar_inactive_color: .0, .0, .0, .0 
        bar_width: '2.5dp'                        
        GridLayout:
            id: guidesonuc_tr
            cols: 1
            spacing: '55dp'
            size_hint_y: None
            height: self.minimum_height 

Python:

class Result(ButtonBehavior, Image):
    pass

class GuideBoxLayout(BoxLayout):
    pass

box3 = GuideBoxLayout()
box_resim = BoxLayout(size_hint_y = None, height = dp(326))
four = Result(size_hint = (1, 1), source = 'images/result.png')
box_resim.add_widget(four)
box3.add_widget(box_resim)
self.ids.guidesonuc_tr.add_widget(box3)

Screenshot of Problem: enter image description here

What i did, not worked

box_resim = BoxLayout(size_hint_y = None, height = dp(326))

changing dp did not work. When i increase dp number, padding increases more.

Could you please help me?

Thanks


Solution

  • See the fit_mode property: https://kivy.org/doc/stable/api-kivy.uix.image.html#adjustment

    fit-mode controls the scaling of the image.