Search code examples
pythonpython-3.xkivykivymd

Change the icon size of MDRectangleFlatIconButton


How could I change the size of the icon inside my button? I tried it many ways, but neither of them worked. I will have 3 of theese buttons, but I want an icon for them as well. How could I change the size of the icon? Changing the border thickness would also be good.

My code:

MDRectangleFlatIconButton:
    text: "Hello"
    icon: "android"
    font_size: "100sp"
    pos_hint: {"center_x": 0.5, "center_y": 0.5}
    size_hint: 0.3, 0.3

enter image description here


Solution

  • I found the answer. You can check what does the button contains if you give it an id property (.kv file) id: testButton and then checking what is inside that button by performing (.py file) self.ids['testButton'].ids in your app container which for me is class AppContainer(MDFloatLayout). The button contains an 'lbl_ic': <WeakProxy to <kivymd.uix.label.MDIcon object at 0x000001879DA4BF28>> which attributes can be changed by self.ids['testButton'].ids["lbl_ic"].font_size = 200.

    Any ideas how to do it in the .kv file?

    The running of my app:

    class MainApp(MDApp):
        def build(self):
            return AppContainer()
    
    
    MainApp().run()