Skip to content

Instantly share code, notes, and snippets.

@driscollis
Created April 8, 2015 16:56
Show Gist options
  • Save driscollis/fdccfae6f310a9296bdd to your computer and use it in GitHub Desktop.
Save driscollis/fdccfae6f310a9296bdd to your computer and use it in GitHub Desktop.
Creating a custom toolbar in wxPython
import wx
########################################################################
class MyCustomToolbar(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
btn_size = (50, 50)
top_sizer = wx.BoxSizer(wx.VERTICAL)
tb_sizer = wx.BoxSizer(wx.HORIZONTAL)
save_ico = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, (16,16))
save_btn = wx.BitmapButton(self, size=btn_size, bitmap=save_ico)
tb_sizer.Add(save_btn, 0, wx.ALL, 5)
print_ico = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR, (16,16))
print_btn = wx.BitmapButton(self, size=btn_size, bitmap=print_ico)
tb_sizer.Add(print_btn, 0, wx.ALL, 5)
delete_ico = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR, (16,16))
delete_btn = wx.BitmapButton(self, size=btn_size, bitmap=delete_ico)
tb_sizer.Add(delete_btn, 0, wx.ALL, 5)
top_sizer.Add(tb_sizer)
h_sizer = wx.BoxSizer(wx.HORIZONTAL)
h_sizer.Add(wx.StaticLine(self), 1, wx.EXPAND)
top_sizer.Add(h_sizer, 1, wx.EXPAND)
self.SetSizer(top_sizer)
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
main_sizer = wx.BoxSizer(wx.VERTICAL)
toolbar = MyCustomToolbar(self)
main_sizer.Add(toolbar, 0, wx.EXPAND)
self.SetSizer(main_sizer)
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Custom Toolbar")
panel = MyPanel(self)
self.Show()
if __name__ == '__main__':
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment