【问题标题】:How to place a label in the bottom-left corner of application using float layout in kivy?如何在kivy中使用浮动布局在应用程序的左下角放置标签?
【发布时间】:2020-06-09 09:36:21
【问题描述】:

目标:

  • 使用 FloatLayout 将标签锚定到左下角。

预期结果:

  • 标签必须位于左下角,单行。

实际结果:

  • 标签在左下角,但它是双线的。

参考代码:

class ScreenThree(Screen):

    def __init__(self, **kwargs):
        super(ScreenThree, self).__init__(**kwargs)
        self.video1 = Video(source="somevideo.mpg")
        float_layout = FloatLayout()
        self.label1 = Label(text="Just a place holder video", opacity=0, pos_hint={"x": 0, "bottom": 1}, size_hint=[0.1, 0.1])
        self.label1.texture_size = self.label1.size
        self.label1.text_size = self.label1.texture_size
        self.label1.halign = "center"
        self.label1.valign = "center"
        self.add_widget(float_layout)
        float_layout.add_widget(self.label1)
        float_layout.add_widget(self.video1, index=1)
        self.video1.opacity = 0

    def on_enter(self):
        self.video1.allow_stretch = True
        self.video1.state = "play"
        self.label1.opacity = 1
        Clock.schedule_once(self._adjust_opacity, 2)

    def _adjust_opacity(self, *dt):
        self.video1.opacity = 1


参考图片:


非常感谢您的阅读。

【问题讨论】:

  • 只是想知道!你想为我的游戏赢得荣誉吗?谢谢!

标签: python python-3.x label kivy python-3.7


【解决方案1】:

在你的行中:

    self.label1 = Label(text="Just a place holder video", opacity=0, pos_hint={"x": 0, "bottom": 1}, size_hint=[0.1, 0.1])

只需将size_hint 更改为[None, 0.1]

    self.label1 = Label(text="Just a place holder video", opacity=1, pos_hint={"x": 0, "bottom": 1}, size_hint=[None, 0.1])

并删除这些行:

    self.label1.texture_size = self.label1.size
    self.label1.text_size = self.label1.texture_size
    self.label1.halign = "center"
    self.label1.valign = "center"

【讨论】:

  • 答案不起作用,但是当我更改它时它起作用了0.2
猜你喜欢
  • 2017-05-19
  • 1970-01-01
  • 1970-01-01
  • 2021-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-08
相关资源
最近更新 更多