I am new to Python. I am writing an application using wxPython and I currently my code that generates a toolbar looks like this:
class Window(wx.Frame)
def __init__(self, parent, plot):
wx.Frame.__init__(self, parent, wx.ID_ANY, "Name", size =(900, 600))
self.Centre()
self.toolbar = self.CreateToolBar(style=(wx.TB_HORZ_LAYOUT | wx.TB_TEXT))
self.toolbar.SetToolBitmapSize((32,32))
self.toolbar.AddLabelTool(3, '', wx.Bitmap('GUI/icons/fileopen.png'))
self.toolbar.AddLabelTool(3, '', wx.Bitmap('GUI/icons/filesave.png'))
self.toolbar.AddSeparator()
self.toolbar.Realize()
I am trying to clean up the code a bit and I want the toolbar to have its own class so when I want to create a toolbar, I simply call it something like this:
toolbar = Toolbar()
My question is how can I rewrite it so it works like that? Currently my code looks like this:
class Toolbar():
def __init__(self):
self.toolbar = self.CreateToolBar(style=(wx.TB_HORZ_LAYOUT | wx.TB_TEXT))
self.toolbar.SetToolBitmapSize((32,32))
self.toolbar.AddLabelTool(3, '', wx.Bitmap('GUI/icons/fileopen.png'))
self.toolbar.AddLabelTool(3, '', wx.Bitmap('GUI/icons/filesave.png'))
self.toolbar.AddSeparator()
self.toolbar.Realize()
I am not quite sure how 'self' works. Do I need to rewrite the init function? How do I fix it? Any help is greatly appreciated. Thanks