Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > wxPython question

Reply
Thread Tools

wxPython question

 
 
Jive
Guest
Posts: n/a
 
      12-17-2004
How the heck do you set the icon on a frame using a .ico file, or a .bmp
file, or whatever? How do you find out how to do something like that?
Apparently there is no documentation to speak of. I tried looking the in
the demo program, but I didn't find the secret..



 
Reply With Quote
 
 
 
 
mefjr75@hotmail.com
Guest
Posts: n/a
 
      12-17-2004
Jive wrote:
> How the heck do you set the icon on a frame using a .ico file, or a

..bmp
> file, or whatever? How do you find out how to do something like

that?
> Apparently there is no documentation to speak of. I tried looking

the in
> the demo program, but I didn't find the secret..

Hello Jive,
# this is a bit old but should still work
# might have to tweak the wx stuff
# because of the namespace change. ex. wxImage -> wx.Image
# image size must be 32h 32w
image = wxImage(file, wxBITMAP_TYPE_JPEG)
image = image.ConvertToBitmap()

icon = wxEmptyIcon()
icon.CopyFromBitmap(image)

frame.SetIcon(icon)

Be sure to look thru the demo it is very informative and is really the
best documention.
As they say use the source Luke.
Hth,
M.E.Farmer

 
Reply With Quote
 
 
 
 
M.E.Farmer
Guest
Posts: n/a
 
      12-17-2004
Messed up it does need the dots.
This should handle bmp ico png gif and several other formats.
Still need to be 32 by 32

wx.InitAllImageHandlers()
image = wx.Image(file, wx.BITMAP_TYPE_ANY)
image = image.ConvertToBitmap()

icon = wxEmptyIcon()
icon.CopyFromBitmap(image)

frame.SetIcon(icon)

Hth,
M.E.Farmer

 
Reply With Quote
 
=?iso-8859-1?B?QW5kcuk=?=
Guest
Posts: n/a
 
      12-17-2004

M.E.Farmer wrote:
> Messed up it does need the dots.
> This should handle bmp ico png gif and several other formats.
> Still need to be 32 by 32
>
> wx.InitAllImageHandlers()
> image = wx.Image(file, wx.BITMAP_TYPE_ANY)
> image = image.ConvertToBitmap()
>
> icon = wxEmptyIcon()
> icon.CopyFromBitmap(image)
>
> frame.SetIcon(icon)
>
> Hth,
> M.E.Farmer


I needed to scale the image down to 16 by 16 on my Windows computer to
make it work.
hth,
André

 
Reply With Quote
 
M.E.Farmer
Guest
Posts: n/a
 
      12-17-2004

André wrote:
> I needed to scale the image down to 16 by 16 on my Windows computer

to
> make it work.


Hello André,

# I actually ran this code
import wx
app = wx.PySimpleApp()
class myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,"Icon Frame",
size=(100,100),pos=(-1,-1))
frame = myframe()
wx.InitAllImageHandlers()
# this image is 32*32 on my computer
image = wx.Image('c:/Python22/pycon.ico', wx.BITMAP_TYPE_ANY)
image = image.ConvertToBitmap()

icon = wx.EmptyIcon()
icon.CopyFromBitmap(image)

frame.SetIcon(icon)

frame.Show()
app.MainLoop()

This works fine for me I am on windows 2000, and pycon.py is 32*32*24
Wonder why you had to resize?

On another note, be sure to check out the tools dir in either the
wxpython dir or wx dir it has a script called img2py.py.

img2py.py -- Convert an image to PNG format and embed it in a Python
module with appropriate code so it can be loaded into
a program at runtime. The benefit is that since it is
Python source code it can be delivered as a .pyc or
'compiled' into the program using freeze, py2exe, etc.

Be sure to use the -i flag so it will convert it to a wxIcon
Once you convert your icon to source using img2py.py you can do this:
import Icon
ICON = Icon.getIcon()
frame.SetIcon(ICON)

Hth,
M.E.Farmer

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[wxPython-users] ANNOUNCE: wxPython 2.6.3.0 Robin Dunn Python 0 03-28-2006 06:03 PM
[wxPython-users] Web based applications are possible with wxPython? Ruben Charles Python 6 10-25-2005 09:41 PM
wxPython - wx package (new style wxPython?) Logan Python 5 12-11-2003 04:12 PM
[PY GUI] interest function in python GUI(wxpython,pyqt) program.wxpython,pyqt ulysses Python 4 10-22-2003 03:28 PM
wxPython looses function "wxPython.wx.miscc" Anand Python 1 07-23-2003 01:59 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57