473,395 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

wxPython question

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..

Jul 18 '05 #1
4 3653
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

Jul 18 '05 #2
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

Jul 18 '05 #3

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é

Jul 18 '05 #4

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

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Anand | last post by:
I am calling a python script from LabVIEW. This is achieved by making a dll call to python22.dll. It works perfectly well for most of my code. I now want to throwup dialog boxes from python. It...
3
by: Equis Uno | last post by:
Hi, I'm trying to run some Python software I downloaded off of sf.net. It's called Boa. It uses wxPython. It appears my install of Python cannot see my install of wxPython.
8
by: Erik Johnson | last post by:
I am looking for some input on GUI libraries. I want to build a Python-driven GUI, but don't really understand the playing field very well. I have generally heard good things about wxPython. I...
14
by: Rod W | last post by:
I'm just starting out on Python but my primary goal is to provide applications with some user interface (GUI). Can someone point me to a good comparison of whether I should use wxPython (with...
4
by: KvS | last post by:
Hi all, I'm pretty new to (wx)Python so plz. don't shoot me if I've missed something obvious ;). I have a panel inside a frame, on which a Button and a StaticText is placed: self.panel =...
2
by: OpenPavilion | last post by:
Hello, did anyone succeed in combining wxpython and a 3d engine (pyogre, crystalblend, panda3d, soya etc.) ? I would like to create an application, which uses wxpython tree, menu and grid...
1
by: Steven W. Orr | last post by:
python-2.3.5 wx-2.6 I just bought the wxPython In Action book and I see that all the examples say to import wx All of our pre-existing code was horribly doing a from wxPython import * I...
4
by: python | last post by:
I'm looking at rewriting some legacy VB applications and am pondering which of the following techniques to use: 1. Browser based GUI with local web server (Browser + wsgiref.simple_server) (I'm...
3
by: mistersulu | last post by:
Hi all: I'm using a wx.ListView object with a multi-threaded wxPython app. The list is dynamically generated and accessed across two or more threads. In spite of the fact that I have checks to...
0
by: gooli | last post by:
The best thing I've found until now is XRCed. It has it's quirks and pitfalls, but it fits the bill. Personally I prefer the previous version (the one that comes with wxPython 2.8.6) and don't...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.