2009-11-28 6 views
0

Je suis en train d'écrire une application de type PAINT en utilisant python.Je suis nouveau sur python, j'utilise wxpython pour GUI. Je dois créer une boîte à outils pour les (lignes, cercle etc etc options). En utilisant l'exemple de création de la barre d'outils à partir de wiki python. Mais ne peut pas comprendre comment le addsimpletool fonctionnewxpython création boîte à outils

importation WX

classe mytoolbar (wx.Frame): def initialisation (self, parent, id, titre):

 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 Je pour créer les images au format .png. Y a-t-un autre moyen de faire ça? J'espère que quelqu'un peut me dire comment cela fonctionne ou me diriger vers n'importe quelle documentation pour cela

+0

Etes-vous intéressé à apprendre Tkinter? –

Répondre

0

J'ai écrit une fonction d'utilité pour ajouter des articles à mes barres d'outils.

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 
Questions connexes