python - 如何在kivy中使用浮动布局在应用程序的左下角放置标签?
问题描述
目标:
- 使用 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
图片供参考:
非常感谢您的阅读。
解决方案
在您的行中:
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"
推荐阅读
- reactjs - 组件挂载前如何获取数据?
- count - 在 Power BI 中按两列分组并将重复数计为 1
- sql - If/Else 语句中的 Golang Postgres 语法错误
- python-3.x - 如何在 Python 中找到一个句子中的整个单词?
- html - 我应该有不同版本的段落吗
- docker - 使用 boltdb 作为存储的 Grafana loki 备份
- html - PayPal 捐赠按钮代码故障 (CSS/HTML)
- pandas - 使用给定函数计算成对距离的矢量化/并行化
- maven - 在 AEM Bundle 中使用 opencsv 时的 Maven 依赖项
- scala - 在 spark scala 中转换为十进制