Search code examples
pythongpswxpythonwxwidgets

How to set multiple image in image frame same time in wxpython


I have been develop a gps system. then i am using python and wx python for make GUI. so i have able to show single map part in image viewer. but is is not sufficient. i want to load separate images same time and show them as a single image in my wx python GUI.

How can i do this with wx python?


Solution

  • You can use OnPaint (in any widget) to draw own elements.

    You can draw many images in widget.

    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 ball-1.png ball-2.png ball-2.png

    MyFrame.png