Kivy 应用程序在 Mac 上看起来不一样

Kivy application looks different on Mac

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

这是第一页的代码:

#: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 下的样子(用两本不同的 Mac 书测试)

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

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

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