Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change button size in kivy?

Tags:

python

kivy

I am writing a program in Python using kivy, and I am unable to change the size of the buttons that transition back and forth between two screens

I can't think of any reason why I'm unable to change its size with something like "size: 75, 50" is it because the class is inherited from Screen instead of Button?

Python File:

import kivy
from kivy.app import App
kivy.require("1.10.1")
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import ScreenManager

class ScreenRoot(Screen):   
    pass

class OtherScreen(Screen):   
    pass

class ScreenUpkeep(ScreenManager):    
    pass

view = Builder.load_file("main.kv")

    class MainApp(App):
        def build(self):
            return view

if __name__ == "__main__":
    MainApp().run()

Corresponding .kv file:

ScreenUpkeep:
    ScreenRoot:
    OtherScreen:    

<ScreenRoot>:
    name: "rootmain"
    Button:
        text: "Next Screen"
        font_size: 40
        on_release: app.root.current = "other"
        size: 75, 50
<OtherScreen>:
    name: "other"
    Button:
        text: "Return"
        font_size: 40
            on_release: app.root.current = "rootmain"

I just want to be able to change the size of the button to be able to include more things like text and pictures on each screen.

like image 315
Hamza Faisal Avatar asked Dec 22 '18 21:12

Hamza Faisal


People also ask

How do you resize a Button in Python?

In order to customize the Button size, we can use the width and height property of the button widget.


1 Answers

You have to disable the size_hint, to visualize it better I will change the font of the button:

Button:
    text: "Next Screen"
    font_size: 12
    on_release: app.root.current = "other"
    size: 75, 50
    size_hint: None, None # <---

enter image description here

like image 193
eyllanesc Avatar answered Oct 14 '22 22:10

eyllanesc