把标签固定在角落?

2024-04-24 20:03:46 发布

您现在位置:Python中文网/ 问答频道 /正文

基维语:

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()

我的标签在窗户中央:

enter image description here

如何将标签锚定在窗口的右下角?在

你会认为

^{pr2}$

会成功的,但是正如^{} documentation指出的

The valign property will have no effect and halign will only have an effect if your text has newlines; a single line of text will appear to be centered even though halign is set to left (by default).


Tags: totextfromimportapphave标签will
2条回答

这看起来就像是将标签添加到AnchorLayout中,然后缩小标签相对于其父窗口小部件的大小,共同实现了我想要的效果。在

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()

产生:

enter image description here

将标签的文本大小设置为其大小,例如以kvtext_size: self.size为单位。文本大小控制文本在其中换行的边界框。在

相关问题 更多 >