【问题标题】:Kivy application looks different on MacKivy 应用程序在 Mac 上看起来不同
【发布时间】:2015-10-08 19:53:29
【问题描述】:

我的 Kivy 应用程序在 Mac 下的外观与在 Windows 或 Linux 下的外观不同。这背后的原因可能是什么?屏幕分辨率?不同操作系统下的安装过程? ... ?

这是第一页的代码:

#:kivy 1.0.9

<MenuButton>:
    font_size: 20
    size_hint: None, None
    height: 75
    width: 300
    pos_hint: {'center_x': .5, 'center_y': .5}

MyScreenManager:
    HomePage:

#### Home Page ##############################################
<HomePage>:
    name: 'Home'
    BoxLayout:
        orientation: 'vertical'
        spacing: 50
        padding: 20 
        BoxLayout:
            orientation: 'vertical'
            size_hint: 1, 0.23
            Label:
                text: 'V2G-Sim'
                font_size: 50
            Label:
                text: 'Vehicle to Grid Simulator'
                font_size: 30

        BoxLayout:
            orientation: 'vertical'
            size_hint: 1, 0.64
            spacing: 20
            RelativeLayout:
                MenuButton:
                    text: 'Create vehicles'
                    on_release: 
                        app.root.transition.direction = 'left'  
                        app.root.current = 'Itinerary'
            RelativeLayout:
                MenuButton:
                    text: 'Grid initialization'
                    on_release: 
                        app.root.transition.direction = 'left'  
                        app.root.current = 'Grid'
            RelativeLayout:
                MenuButton:
                    text: 'Simulate vehicles'
                    on_release: 
                        app.root.transition.direction = 'left'  
                        app.root.current = 'SimulationType'
            RelativeLayout:
                MenuButton:
                    text: 'Visualizations'
                    on_press:
                        root.raise_popup()
                    on_release: 
                        root.visualization()

        BoxLayout:
            orientation: 'horizontal'
            size_hint: 1, 0.13
            spacing: 30
            Button:
                text: 'Project status'
                font_size: 20
                size_hint: 0.7, 1
                on_release: 
                    app.root.transition.direction = 'left'  
                    app.root.current = 'ProjectStatus'
            Button:
                text: 'Exit'
                font_size: 20
                size_hint: 0.7, 1
                on_release:
                    root.exit_app()

这是 Windows/Linux 发行版下的外观:

这是 Mac 下的外观(用 2 台不同的 Mac 书测试)

【问题讨论】:

    标签: user-interface kivy


    【解决方案1】:

    mac 可能有一个高 dpi 显示器,因此您对按钮和字体大小的固定大小声明是实际大小的一半,因为它们以像素为单位。

    您可以使用 kivy.metrics 中的 dp 函数(在 kv 中自动导入)来避免这种情况,例如font_size: dp(20).

    请注意,屏幕都有些不同,并且可能无法正确报告它们的 dpi,因此您可能仍会在不同的硬件上得到一些(较小的)差异。

    【讨论】:

    • 是的,我昨天自己想通了。我很惊讶默认单位是像素。我还使用 sp 而不是 dp 来确保考虑到用户的设置。不过还是谢谢。
    猜你喜欢
    • 2020-12-16
    • 2016-03-23
    • 1970-01-01
    • 1970-01-01
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    相关资源
    最近更新 更多