Hi,

#!/usr/bin/python

# panels.py

import wx


class Panels(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)

hbox = wx.BoxSizer(wx.HORIZONTAL)
splitter = wx.SplitterWindow(self, -1)

vbox1 = wx.BoxSizer(wx.VERTICAL)
panel1 = wx.Panel(splitter, -1)
panel11 = wx.Panel(panel1, -1, size=(-1, 40))
panel11.SetBackgroundColour('#53728c')
st1 = wx.StaticText(panel11, -1, 'Feeds', (5, 5))
st1.SetForegroundColour('WHITE')

panel12 = wx.Panel(panel1, -1, style=wx.BORDER_SUNKEN)
panel12.SetBackgroundColour('WHITE')

vbox1.Add(panel11, 0, wx.EXPAND)
vbox1.Add(panel12, 1, wx.EXPAND)

panel1.SetSizer(vbox1)

vbox2 = wx.BoxSizer(wx.VERTICAL)
panel2 = wx.Panel(splitter, -1)
panel21 = wx.Panel(panel2, -1, size=(-1, 40), style=wx.NO_BORDER)
st2 = wx.StaticText(panel21, -1, 'Articles', (5, 5))
st2.SetForegroundColour('WHITE')

panel21.SetBackgroundColour('#53728c')
panel22 = wx.Panel(panel2, -1, style=wx.BORDER_RAISED)

panel22.SetBackgroundColour('WHITE')
vbox2.Add(panel21, 0, wx.EXPAND)
vbox2.Add(panel22, 1, wx.EXPAND)

panel2.SetSizer(vbox2)

toolbar = self.CreateToolBar(self)
toolbar.AddLabelTool(1, 'Exit', wx.Bitmap('icons/stock_exit.png'))
toolbar.Realize()
self.Bind(wx.EVT_TOOL, self.ExitApp, id=1)

hbox.Add(splitter, 1, wx.EXPAND | wx.TOP | wx.BOTTOM, 5)
self.SetSizer(hbox)
self.CreateStatusBar()
splitter.SplitVertically(panel1, panel2)
self.Centre()
self.Show(True)


def ExitApp(self, event):
self.Close()


app = wx.App()
Panels(None, -1, 'Panels')
app.MainLoop()


createToolbar gives an error. (Look at the Attachment). How may I get this to work successfully.

BRgds,

kNish

You got to use code tags around your code!
http://www.daniweb.com/forums/announcement114-3.html

This is what our instructor gave as for a wxPython toolbar example:

# wx.ToolBar(parent, id, pos, size, style, name)
# images from DrPython\bitmaps\16\

import wx

class MyToolBar(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(350, 250))

        vbox = wx.BoxSizer(wx.VERTICAL)
        toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER)
        toolbar.AddSimpleTool(1, wx.Image('new.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'New', '')
        toolbar.AddSimpleTool(2, wx.Image('open.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Open', '')
        toolbar.AddSimpleTool(3, wx.Image('save.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Save', '')
        toolbar.AddSeparator()
        toolbar.AddSimpleTool(4, wx.Image('exit.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap(), 'Exit', '')
        toolbar.Realize()
        vbox.Add(toolbar, 0, border=5)
        self.SetSizer(vbox)
        self.statusbar = self.CreateStatusBar()
        #self.Centre()

        self.Bind(wx.EVT_TOOL, self.OnNew, id=1)
        self.Bind(wx.EVT_TOOL, self.OnOpen, id=2)
        self.Bind(wx.EVT_TOOL, self.OnSave, id=3)
        self.Bind(wx.EVT_TOOL, self.OnExit, id=4)

    def OnNew(self, event):
        self.statusbar.SetStatusText('New Command')
        # add proper code here later

    def OnOpen(self, event):
        self.statusbar.SetStatusText('Open Command')
        # add proper code here later
        
    def OnSave(self, event):
        self.statusbar.SetStatusText('Save Command')
        # add proper code here later
        
    def OnExit(self, event):
        self.Close()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyToolBar(None, -1, 'Test wx.ToolBar')
        frame.Show(True)
        return True

app = MyApp(0)
app.MainLoop()

I think there are a couple of things missing in your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.