[wxpython-users] where we put the .png files?

Mike Driscoll mdriscoll at co.marshall.ia.us
Thu May 1 14:22:25 PDT 2008


Abdessamad EL GON-NOUNI wrote:
> It dosn't work, he gives me the msg "Can'l load image from file 
> 'Exit.png':files does not exist"
>

Make sure the path to your png is correct. Also, check out 
wx.ArtProvider for standard icons. I use img2py if I need custom icons 
because it's easier to embed them in my application.

> I have another problem: when I want to bind an element from the 
> menubar to an event, the program doesn't recognize the method, I have 
> this error msg: 'MainWindow' object has no attribute 'OnExit'

Are you talking about a menu event or a toolbar event? Here's a generic 
way to create code for a toolbar (I created a ):

<code>

def createToolbar(self):
    toolbar = self.CreateToolBar(wx.TB_3DBUTTONS|wx.TB_TEXT)
    self.toolbar.SetToolBitmapSize((16,16))
    print_ico = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR, 
(16,16))
    printTool = self.toolbar.AddSimpleTool(wx.ID_ANY, print_ico, 
'Print', 'Sends Timesheet to Default Printer')
    self.Bind(wx.EVT_MENU, self.OnPrint, sendTool)       
    toolbar.Realize()

</code>

And here's how I do menubar code for the same function as above:

<code>

menubar = wx.MenuBar()
fileMenu = wx.Menu()
printDefault_menu_item = fileMenu.Append(wx.ID_ANY, '&Print\tCtrl+P', 
'Prints to Default Printer')
self.Bind(wx.EVT_MENU, self.onPrintDefault, printDefault_menu_item)
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)

</code>



>
> 2008/5/1 Cody Precord <codyprecord at gmail.com 
> <mailto:codyprecord at gmail.com>>:
>
>     Hello,
>
>     You can put them anywhere you want to, your program just has to be
>     able to read them and create a wx.Bitmap from them to use your
>     toolbar, ect...
>
>     You may also want to look at the img2py script that comes with
>     wxpython for embedding the png images in python code.
>
>     Regard,
>
>     Cody
>
>
>     On May 1, 2008, at 3:19 PM, Abdessamad EL GON-NOUNI wrote:
>
>         hello,
>            I'm working on a graphic interface with wxpython and I want
>         to make a tool bar with icons. but I don't know where should I
>         put these icons so that they can be shown. I use eclipse to
>         develop my application. any idea?
>         _______________________________________________
>
Hope that helps,

Mike


More information about the wxpython-users mailing list