2013-10-22 21 views
0

我想在下面的大小函數中使用wxpython繪製佈局是繪製佈局的代碼我如何以%的形式提及大小(ex size =( 「20%」,「20%」)或如何像素轉換成入%。如何在wxpython中以%的形式繪製佈局大小

# -*- coding: utf-8 -*- 

# size.py 

import wx 

class Example(wx.Frame): 

    def __init__(self, parent, title): 
     super(Example, self).__init__(parent, title=title, 
      size=(250, 200)) 

     self.Show() 


if __name__ == '__main__': 

    app = wx.App() 
    Example(None, title='Size') 
    app.MainLoop() 

回答

1

你必須檢查屏幕和計算百分比大小,因爲你只能指定像素大小。所以你的init應該是這樣的:

def __init__(self, parent, title, percent): 

    super(Example, self).__init__(parent, title=title) 
    screen_size_x, scree_size_y = wx.GetDisplaySize() 
    size_x = round(screen_size_x*percent,0) 
    size_y = round(screen_size_y*percent,0) 
    self.SetSize((size_x, size_y)) 
    self.Show() 

然後你調用示例框體W ith 示例(無,title ='Size',percent = 0.2)

+0

謝謝..但是如何使用python以動態方式讀取屏幕尺寸 – passionTime

+0

我不明白...請解釋一下動態?屏幕尺寸不會改變。 – yemu

+0

假設如果我在不同的顯示器上使用此腳本或自動顯示應檢測...如果這將是一個非常有用的... thanx – passionTime

相關問題