A
A
Andrei1penguin12021-05-07 20:10:10
Python
Andrei1penguin1, 2021-05-07 20:10:10

Why is the button nailed to the bottom left corner?

Good day, there is a python code:

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.graphics import Color, Rectangle
from kivy import Config
from kivy.lang import Builder
Config.set("graphics", "fullscreen", "auto")
Builder.load_file("app.kv")

class MyWidget(Widget):

    def __init__(self):
        super().__init__()
        self.size_hint = 0.2, 1

class MainWidget(App):

    def build(self):
        main_widget = BoxLayout(orientation="horizontal")
        main_widget.add_widget(MyWidget())
        return main_widget

if __name__ == '__main__':
    MainWidget().run()

KV code:
<MyWidget>:
    canvas:
        Color:
            rgba: (0.3, 0.3, 0.3, 1)
        Rectangle:
            pos: self.pos
            size: self.size
    Button:
        text: "button"
        size_hint: 0.5, 1
        pos_hint: {"center_y": .5, "center_x": .5}

But the button button is pressed to the lower left edge, and even with the default dimensions of 100x100
Please tell me what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy _, 2021-05-07
@GeneD88

Add the desired coordinates to the kv file for the button:
pos: 100, 100

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question