Buttons with dynamic images with kivy

Asked

Viewed 634 times

0

Problem

I have a button with circular image, with the image in ratio 1:1, and when executing the code (below) the program generates a screen with ratio also 1:1, but it is possible to resize the screen and change its proportion and size, However, the image does not grow together as the screen and occupies a smaller proportional space. I tried to set values for the size_hint:, but it distorts the image, less in a single proportion. How can I make this button adaptable to any proportion and size, without distortion and with the same proportional space?

Generated screen (1:1)

Tela gerada

Resized screen (16:9)

Tela redimensionada

Code

import kivy
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image

class FloatingApp(App):

    def build(self):
        return FloatLayout()

flApp = FloatingApp()

flApp.run()

Archive . Kv

<Botao@Button>:
    font_size: 32
    color: 1, 1, 1, 1
    size: 138, 138
    background_normal: 'bd.png'
    background_down: 'bd1.png'
    background_color: 0.88, 0.88, 0.88, 1  
    size_hint: None, None

<FloatLayout>:
    Botao:

        text:"Botao"
        pos_hint: {"center_x": .5, "center_y": .5}
  • for the image to adapt to the size can use the property size_hint

  • Yes, but in this case, it adapts to the screen size, and distorts the image. the goal is to be able to adapt, without distortion

1 answer

0


We can set the width with size_hint and the height is equal.

size_hint: 0.1, None
height: self.width

Browser other questions tagged

You are not signed in. Login or sign up in order to post.