Attach a shortcut to the corner?

In Qiwi:

from kivy.app import App
from kivy.uix.label import Label

class TestApp(App):
    def build(self):
        label = Label(text="TEST")
        return label

TestApp().run()

My label is in the center of the window:

enter image description here

How can I snap my label to the lower right corner of the window?

You think,

label.halign = 'right'
label.valign = 'bottom'

would do the trick, but as the Labeldocumentation points out ,

The property valignwill have no effect, but halignwill have an effect if your text has new lines; one line of text will be centered, although halignset to the left (default).

+4
source share
2 answers

It looks like adding a label to AnchorLayout and then reducing the size of the label relative to its parent widget, as well as achieving what I want.

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.anchorlayout import AnchorLayout

class TestApp(App):
    def build(self):
        anchor_layout = AnchorLayout(anchor_x='right', anchor_y='bottom')
        label = Label(text="TEST")
        label.size_hint = (0.1, 0.1)
        anchor_layout.add_widget(label)
        return anchor_layout

TestApp().run()

It produces:

enter image description here

+2
source

text_size , . kv text_size: self.size. Text_size , .

+1

Source: https://habr.com/ru/post/1605677/


All Articles