2015-10-08 107 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 **來確保用戶的設置將被考慮在內。不過謝謝。 –

相關問題