python - 如何使用 kivy 放置更好的尺寸和位置提示
问题描述
我目前正在开发一个用于移动设备的 kivy 应用程序。我有一些标签和按钮,如果我运行程序,它们的位置很好,但是当我缩小窗口时,标签和按钮中的文本会离开屏幕。任何人都可以提出更好的位置和大小提示,以便即使最小化窗口它们也不会离开屏幕?这是我的代码:
Label:
color: 1,0,0,1
pos_hint:{ "top":5,"left": 1}
size_hint:1,1
text: "Which number cannot be written in roman numbers?"
font_size: 30
BoxLayout:
Button:
pos_hint:{"top": 1,"left": 1}
size_hint:1,1
text: "0"
font_size: 30
size: 30,30
on_release:
self.background_color = 250,255,0,0.3
Button:
pos_hint:{"top": 1,"left": 1}
size_hint:1,1
text: "1 million"
font_size: 30
size: 30,30
on_release:
self.background_color = 1, 0, 0, 1
BoxLayout:
Button:
pos_hint:{"top": 1,"left": 1}
size_hint:1,1
text: "999"
font_size: 30
size: 30,30
on_release:
self.background_color = 1, 0, 0, 1
Button:
pos_hint:{"top": 1,"left": 1}
size_hint:1,1
text: "10 million"
font_size: 30
size: 30,30
on_release:
self.background_color = 1, 0, 0, 1
解决方案
四个你的Label
and Button
,你可以只设置文本的大小,或者根据需要缩短文本或者向任意方向扩展,例如:
Label:
text: 'this is some really long text which will be shortened to keep it inside the Label bounds'
text_size: self.size
shorten: True
shorten_from: 'right'
您可以对Button
. 我猜您可以做的另一件事是根据需要扩展Label
or Button
,例如:
Label:
text_size: [self.parent.width, None]
size: self.texture_size
在这里,当文本的水平尺寸变得太大时,文本将简单地增长到新的一行
推荐阅读
- excel - 使用 With(语法)格式化图表图例
- python - 是否可以一步完成这些?
- javascript - AWS Cost Explorer:Lambda 错误:getCostForecast 不是函数
- asp.net - 像在队列系统中一样逐一导航数据库记录
- android - 需要帮助使用 CheckBoxes 删除 Android ListView 项目
- c# - 如何由用户制作带有可移动窗口的 UI
- php - 如何从 Codeigniter 中的 JS 文件发送 CSRF 令牌?
- django - 将管理站点自定义按钮重定向到视图
- bash - 我想添加一个计数器并在此日期 20180101 中添加 70 示例是当计数器大于 31 时在日期 20180101 中添加 70 否则 j+1
- spring - Spring中的Bean初始化之后是否发生了静态初始化