Hi

I am new to this forum so please excuse me if am not following the etiquette. I am a beginner in wxpython. For a project I need to create a color palette. Please check and tell me what I am doing wrong. Any help,suggestion,code snippet is welcome.

import wx
from wx.lib import buttons
class toolbar(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Sketch Frame",
        size=(1024,700))
        self.sketch = SketchWindow(self, -1)
   
      #  wx.Panel.__init__(self, parent, -1, style=wx.RAISED_BORDER)
        #self.topFrame = topFrame
        colorGrid = self.createColorGrid(parent)
        self.layout(colorGrid)
        
    def createColorGrid(self,parent):
        
        colorGrid =wx.GridSizer(cols=2,hgap=2,vgap=2)
        for each in colordata():
         bmp=self.MakeBitMap(each)
         bt = buttons.GenBitmapToggleButton(self, -1, bmp, size=2)
         self.Bind(wx.EVT_BUTTON, self.OnSetColor, bt)
         colorGrid.Add(bt, 0)
        return colorGrid
    def colordata(self):
        return ('Light Grey', 'Yellow', 'Goldenrod', 'gold', 'Orange',
            'Blue', 'Purple', 'Light Blue', 'Cyan', 'Light Steel Blue',
            'Cadet Blue', 'Aquamarine', 'pale green', 'Green', 'Forest Green')

    def layout(self, colorGrid):
        box = wx.BoxSizer(wx.HORIZONTAL)
        box.Add(colorGrid, 0, wx.ALL, self.SPACING)
        self.SetSizer(box)
        box.Fit(self)

    def MakeBitmap(self, color):
        bmp = wx.EmptyBitmap(16, 15)
        dc = wx.MemoryDC(bmp)
        dc.SetBackground(wx.Brush(color))
        dc.Clear()
        dc.SelectObject(wx.NullBitmap)
        return bmp

    def OnSetColor(self, event):
        print " hoho"

class SketchWindow(wx.Window):
    def __init__(self, parent):
        wx.Window.__init__(self, parent, ID)

try:
    
 if __name__=='__main__':
    app=wx.PySimpleApp()
    frame=toolbar(None)
    frame.Show(True)
    app.MainLoop()
finally:
    del app

Thanks

Edited 7 Years Ago by vegaseat: added code tags

This article has been dead for over six months. Start a new discussion instead.