2015-10-08 90 views
2

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

这里是第一页的代码:

#: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发行版的外观:enter image description here

这是苹果在外观(有2个不同的Mac书进行测试) enter image description here

回答

2

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

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

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

+0

是的,我昨天自己想出了这个。我很惊讶默认单位是像素。此外,我使用** sp **而不是** dp **来确保用户的设置将被考虑在内。不过谢谢。 –

相关问题