在用python做简单的画板,请问为什么无法访问图片

img


import wx

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None,title="My Frame",size=(800,600),pos=(100,100))
        #Panels
        top_Panel=wx.Panel(self,size=(750,400))
        bottom_Panel=wx.Panel(self,size=(750,50))
        color_Panel = wx.Panel(self,size=(750,50))
        #Layout
        vBox = wx.BoxSizer(wx.VERTICAL)
        vBox.Add(top_Panel,proportion=1, flag=wx.CENTER|wx.TOP,border=10)
        vBox.Add(bottom_Panel,proportion=1, flag=wx.CENTER|wx.TOP,border=10)
        vBox.Add(color_Panel,proportion=1, flag=wx.CENTER|wx.TOP,border=10)
        #top widgets and layout
        self.staticText = wx.StaticText(parent=top_Panel,label="draw a shape")
        topBox=wx.BoxSizer(wx.HORIZONTAL)
        topBox.Add(self.staticText,proportion=1, flag=wx.CENTER)
        top_Panel.SetSizer(topBox)

        #bottom widgets and layout

        imgs=['pen','eraser','plus','minus']
        bitmaps=['C:\\img\\'+imgs[i]+".png" for i in range(4)]
        bmps = [wx.Image(bitmaps[i],wx.BITMAP_TYPE_PNG).ConvertToBitmap()
         for i in range (4)]
        print(bmps)
        self.buttons=[wx.BitmapButton(bottom_Panel,i,bmps[i])
        for i in range(4)]

        # binding an event
        #self.Bind(wx.EVT_BUTTON,self.button_Click,self.buttons[0])
        #1
        #2
        bottomBox=wx.BoxSizer(wx.HORIZONTAL)
        for i in range(4):
            bottomBox.Add(self.buttons[i],proportion=1, flag=wx.CENTER)
        bottom_Panel.SetSizer(bottomBox)

        #Color Panel
        self.colors = ['#FAEBD7','#00FFFF','#7FFFD4','#F0FFFF',
        '#F5F5DC','#FFE4C4','#000000','#FFEBCD',
        '#0000FF','#8A2BE2','#A52A2A','#DEB887',
        '#5F9EA0','#7FFF00','#D2691E','#FF7F50']
        self.color_Btns=[wx.Button(parent=color_Panel,id = i+10)
        for i in range(16)]
        for i in range(16):
            self.color_Btns[i].SetBackgroundColour(self.colors[i])
            self.Bind(wx.EVT_BUTTON,self.button_Click,self.color_Btns[i])    
        color_gridSizer = wx.GridSizer(rows=2,cols=8,gap=wx.Size(5,10))
        color_gridSizer.AddMany([(self.color_Btns[i],0,wx.EXPAND) for i in range(16)])
        color_Panel.SetSizer(color_gridSizer)
        # Frame 
        self.SetSizer(vBox)

    def button_Click(self,event):
        eventid = event.GetId()
        print(eventid)
        self.staticText.SetBackgroundColour(self.colors[eventid-10])
        self.staticText.SetLabelText("Start to draw ....")
app = wx.App()

fm = MyFrame()

fm.Show()

app.MainLoop()

文件目录不存在? 确定拼接后的路径或目录是否存在