Buttons with dynamic images with kivy
Problem
I have a button with circular image, with the image in 1:1 ratio, and when executing the code (below) the program generates a screen with aspect ratio also of 1:1, but it is possible to resize the screen and change its aspect ratio and size, however, the image does not grow together as the screen and occupies a smaller proportional space. I tried to set values for size_hint:
, but it distorts the image, less in a single aspect ratio. How can I make this button adaptable in relation to at any ratio and Size, without distortions and with the same proportional space?
Generated fabric (1:1)
Resized canvas (16:9)
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()
File .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}
0
1 answers
We can set the width with the size_hint and the height is equal.
size_hint: 0.1, None
height: self.width
0
Author: tomasantunes, 2018-12-13 13:07:16