[Python] Python Kivy Button text_size = self.size wraps in button way before it should

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm coding an application in Kivy (seriously impressive library).

    I'm coming up against an interesting issue, and wondering if I'm missing something and/or if there's a fix.

    [​IMG]

    I created some buttons in the app (I've actually converted to an apk and installed it on my phone and this is a screenshot from there, but the same thing happens on the emulator).

    You'll notice that the word "Random" breaks into two lines with "Rando" and "m".

    The buttons' text_size is linked to the buttons's size property, so the code for the text was like this:

    for button in self.button_layout.children:
    button.text_size = button.size
    button.halign = 'center'
    button.valign = 'middle'


    From my perspective, this should have allowed "Random" and "Breadth" to have fitted on one line quite easily. I can only guess that there's a race condition when it does the layout.

    When I run

    >>python main.py


    And size it similar to the phone size, it looks like this (which is what I want):

    [​IMG]

    What can I do to make sure that it renders the screen like this? Any common traps that I might be missing.

    Continue reading...

Compartilhe esta Página