如何在 kivy 中使用浮动布局在应用程序的 bottom-left 角放置标签?
How to place a label in the bottom-left corner of application using float layout in kivy?
目标:
- 使用 FloatLayout 将标签锚定到 bottom-left。
预期结果:
- 标签必须在bottom-left角上,单线。
实际结果:
- 标签在 bottom-left 上,但它是 double-lined。
参考代码:
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
参考图片:
非常感谢您的阅读。
在你的行中:
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"
目标:
- 使用 FloatLayout 将标签锚定到 bottom-left。
预期结果:
- 标签必须在bottom-left角上,单线。
实际结果:
- 标签在 bottom-left 上,但它是 double-lined。
参考代码:
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
参考图片:
非常感谢您的阅读。
在你的行中:
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"