A
A
Ander8132019-04-07 15:42:44
Python
Ander813, 2019-04-07 15:42:44

How to change widget background in kivy?

The examples give something similar, but what should I do if I do not specify the exact position of the widgets.

from kivy.graphics import *
with self.canvas:
    # Add a red color
    Color(1., 0, 0)

    # Add a rectangle
    Rectangle(pos=(10, 10), size=(500, 500))

When I try to use this:
with logo_background.canvas:
            Color(.29, .46, .66, 1)
            Rectangle(pos = logo_background.pos, size = logo_background.size)

it just creates a 100x100 square in the left corner.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Ander813, 2019-04-07
@Ander813

Found as for me a very crutch solution

class LogoBackground(Label):
    def on_size(self, *args):
        self.canvas.before.clear()
        with self.canvas.before:
            Color(.29, .46, .66, 1)
            Rectangle(pos=self.pos, size=self.size)

logo = LogoBackground(text = "text", size_hint = (1, .05))

at the same time, in theory, the same option does not work (creates a square 100 by 100)
logo = Label(text = "Text", size_hint = (1, .05))
with logo.canvas.before:
    Color(.29, .46, .66, 1)
    Rectangle(pos=logo.pos, size=logo.size)

Maybe someone can explain why this is so or how to make it less miserable.

M
maximw, 2017-02-01
@maximw

You may not be passing the first argument, which is needed in a procedure call. Manual .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question