【问题标题】:How to put better size and pos hints with kivy如何使用 kivy 放置更好的尺寸和位置提示
【发布时间】:2020-03-17 07:52:23
【问题描述】:

我目前正在开发一款适用于移动设备的 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

【问题讨论】:

    标签: python android button kivy kivy-language


    【解决方案1】:

    四个你的Label和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 或Button,例如:

    Label:
        text_size: [self.parent.width, None]
        size: self.texture_size
    

    这里,当文本的水平尺寸变得太大时,文本会简单地增长到一个换行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 2018-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多