2016-11-21 59 views
0

我已經制定了GPS系統。那麼我使用python和wx python來製作GUI。所以我能夠在圖像查看器中顯示單個地圖部分。但是是不夠的。我想加載單獨的圖像同時,並顯示他們在我的WX蟒蛇GUI單個圖像。如何設置圖像幀同時爲多個圖像在wxPython

我怎麼能做到這一點與WX蟒蛇?

+0

,也許你可以使用[wx.GridSizer](http://zetcode.com/wxpython/layout/ )佈局管理器將圖像放入單元格中(請參閱計算器中的按鈕示例)或者您可以覆蓋[OnEraseBackground](http://www.blog.pythonlibrary.org/2010/03/18/wxpython-putting-a-background- image-on-a-panel /)功能可自由繪製窗口/小部件。 – furas

+1

請解釋「單獨的圖像...作爲一個單一的形象」更好。你想用瓷磚嗎? –

回答

1

您可以使用OnPaint(在任何部件)來繪製自己的元素。

您可以在小部件中繪製很多圖像。

import wx 

class MyFrame(wx.Frame): 

    def __init__(self): 
     wx.Frame.__init__(self, None, size=(300, 200)) 

     #self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) 

     # two images 
     self.image1 = wx.Bitmap("ball-1.png") 
     self.image2 = wx.Bitmap("ball-2.png") 

     # assign own function to draw widget 
     self.Bind(wx.EVT_PAINT, self.OnPaint) 

     self.Show() 

    def OnPaint(self, evt): 
     dc = wx.PaintDC(self) 

     # draw own elements 

     width = self.image1.GetWidth() 
     height = self.image1.GetHeight() 

     dc.DrawBitmap(self.image1, 0, 0) 
     dc.DrawBitmap(self.image2, width, 0) 

     dc.DrawBitmap(self.image2, 0, height) 
     dc.DrawBitmap(self.image1, width, height) 

if __name__ == '__main__': 

    app = wx.App() 
    MyFrame() 
    app.MainLoop() 

ball-1.png球1.png ball-2.png球2.png

MyFrame.png