如何在wxpython中同时设置图像帧中的多个图像

如何在wxpython中同时设置图像帧中的多个图像,python,gps,wxpython,wxwidgets,Python,Gps,Wxpython,Wxwidgets,我一直在开发gps系统。然后我使用python和wx python制作GUI。所以我可以在图像查看器中显示单个地图部分。但这还不够。我想同时加载单独的图像,并在我的wx python GUI中将它们显示为单个图像 如何使用wx python实现这一点?您可以使用OnPaint(在任何小部件中)绘制自己的元素 您可以在小部件中绘制许多图像 import wx class MyFrame(wx.Frame): def __init__(self): wx.Frame.__

我一直在开发gps系统。然后我使用python和wx python制作GUI。所以我可以在图像查看器中显示单个地图部分。但这还不够。我想同时加载单独的图像,并在我的wx python GUI中将它们显示为单个图像


如何使用wx python实现这一点?

您可以使用
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 ball-2.png


您可以使用
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 ball-2.png

也许您可以使用布局管理器将图像放入单元格(参见计算器中按钮的示例),或者您可以覆盖函数以在窗口/小部件中自由绘制。请更好地解释“单独图像…作为单个图像”。您想使用平铺吗?也许您可以使用布局管理器将图像放入单元格(请参见计算器中的按钮示例),或者您可以覆盖函数以在窗口/小部件中自由绘制。请更好地解释“单独图像…作为单个图像”。你想用瓷砖吗?