Search code examples
pythonimagebuttonbackgroundkivy

KIVY: Button background not displayed despite source being specified


I am having a strange issue in Kivy where a button's background_normal and background_down values are being set to a directory path which is 'images/icons/software_icon.jpg' however when my program is started, the image is not displayed and I am given the basic grey box that Kivy buttons default to. My guess is that Kivy is not finding the image in the directory I've given it however I have ensured that the image is in the correct directory. This method has worked with all my other buttons in my code so I'm not sure what's going on. Here is my code:

    Button:

        id: power_button

        text: ''
        background_normal: 'images/icons/power_icon.jpg'
        background_down: 'images/icons/power_icon.jpg'
        center_x: 1520
        center_y: 120
        texture: self.texture
        height: 50
        width: 50
        opacity: 0
        disabled: True
        on_press:
            root.powerOff()
    Button:

        id: settings_button

        text: ''
        background_normal: 'images/icons/settings_icon.jpg'
        background_down: 'images/icons/settings_icon.jpg'
        center_x: 1520
        center_y: 190
        texture: self.texture
        height: 50
        width: 50
        opacity: 0 
        disabled: True
        on_press:
            pass 

    Button:

        id: os_button

        text: ''
        background_normal: 'images/icons/software_icon.jpg'
        background_down: 'images/icons/software_icon.jpg'
        center_x: 1520
        center_y: 260
        texture: self.texture
        height: 50
        width: 50
        opacity: 0
        disabled: True 
        on_press:
            pass

The output: image of the issue

Any ideas as to what I should do now?


Solution

  • I found the solution! I'm still unclear as to why this made any difference but I am not complaining. Anyways here is the newly updated code for the button in the .kv file:

        Button:
    
            id: os_button
    
            text: ''
            center_x: 1910
            center_y: 260
            texture: self.texture
            height: 50
            width: 50
            opacity: 0
            disabled: True 
            on_press:
                pass
    
            Image:
                source: 'images/icons/soft_icon.jpg'
                size: os_button.size
                pos: os_button.pos
    

    So just adding the Image attribute instead of the background_normal and background_down attributes cleared up the issue. Hopefully this helps anyone having the same issue in the future!

    New result: FINAL RESULT