0
votes

I am writing a PAINT like application using python.I am new to python, am using wxpython for GUI. I have to create a toolbox for the (lines, circle etc etc options).Using the toolbar creation example from python wiki. But cannot understand how the addsimpletool works

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_VERTICAL | wx.NO_BORDER)

             toolbar.AddSimpleTool(1,wx.Image('stock_new.png',wx.BITMAP_TYPE_PNG).ConvertToBitmap(),   'New', '')


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

   app = MyApp(0)
   app.MainLoop()

Di I have to create the images in .png format. Is there any other way to do this? I hope someone can tell me how it works or point me to any documentation for it

1
Might you be interested in learning Tkinter?Noctis Skytower

1 Answers

0
votes

I wrote a utility function to add items to my toolbars.

def tool_item(window, toolbar, label, func, icon):
    icon = wx.Bitmap('icons/%s' % icon)
    item = toolbar.AddSimpleTool(-1, icon, label)
    if func:
        window.Bind(wx.EVT_TOOL, func, id=item.GetId())
    return item

...

def create_toolbar(self):
    # create toolbar
    toolbar = wx.ToolBar(self, -1, style=wx.HORIZONTAL|wx.TB_FLAT|wx.TB_NODIVIDER)
    toolbar.SetToolBitmapSize((18,18)) # looks better with 16x16 icons

    # add items to toolbar
    tool_item(self, toolbar, 'New Project', self.on_new_project, 'page.png')
    tool_item(self, toolbar, 'Open Project', self.on_open_project, 'folder_page.png')
    toolbar.AddSeparator()
    # (etc...)

    # finish up
    toolbar.Realize()
    toolbar.Fit()
    return toolbar