【问题标题】:Packaged Kivy app visually incorrect打包的 Kivy 应用在视觉上不正确
【发布时间】:2017-07-17 20:34:58
【问题描述】:

我有一个简单的表格应用程序,我使用 Pyinstaller for os x 打包。如果我运行main.py,小部件会正确显示:

按照docs打包app后打开.app标签大小等乱七八糟。事实上,如果还有其他小部件,它们的大小也不会正确。

我的kv 或一般代码是否存在可能导致此问题的问题?我有一个大型应用程序,我已经尝试打包一个星期了,我已经把事情归结为最后一点。

其他信息:我在 Mac Yosemite 上。如果需要,我可以提供日志,但我没有看到任何错误。

这里是main.py

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.properties import BooleanProperty, ObjectProperty
from kivy.lang import Builder

kv = """
<Cell>:
    size_hint: (None, None)
    width: 400
    height: 60
    canvas.before:
        Color:
            rgba: [0.23, 0.23, 0.23, 1] if self.is_even else [0.2, 0.2, 0.2, 1]
        Rectangle:
            pos: self.pos
            size: self.size

<Table>:
    grid: grid
    bar_width: 25
    scroll_type: ['bars', 'content']
    bar_color: [0.4, 0.7, 0.9, 1]
    bar_inactive_color: [0.2, 0.7, 0.9, .5]
    do_scroll_x: True
    do_scroll_y: True
    GridLayout:
        id: grid
        cols: 15
        rows: 30
        size_hint: (None, None)
        width: self.minimum_width
        height: self.minimum_height
"""

Builder.load_string(kv)


class Cell(Label):
    is_even = BooleanProperty(None)


class Table(ScrollView):

    grid = ObjectProperty(None)

    def __init__(self, *args, **kwargs):
        super(Table, self).__init__(*args, **kwargs)

        for i in range(30):
            for j in range(15):
                text = "data row: {}, column: {}".format(i, j)
                self.grid.add_widget(Cell(text=text, is_even=i % 2 is 0))


class TestApp(App):
    def build(self):
        return Table()


if __name__ == '__main__':
    TestApp().run()

【问题讨论】:

  • 也许您需要根据您的尺寸使用 dp 或 sp。见kivy.org/docs/api-kivy.metrics.html
  • 谢谢!我认为这就是问题所在。做一个答案,如果你愿意,我会标记它。

标签: python kivy pyinstaller


【解决方案1】:

您可能需要将dpsp 用于您的尺寸。见kivy.org/docs/api-kivy.metrics.html

【讨论】:

    猜你喜欢
    • 2015-09-03
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 2021-04-07
    • 1970-01-01
    • 2021-02-07
    • 2019-07-23
    • 2023-03-27
    相关资源
    最近更新 更多