MyTetra Share
Делитесь знаниями!
конвертация иконки для exe wxPython
Время создания: 23.07.2017 09:14
Текстовые метки: code
Раздел: Python - PyWx - Icons
Запись: xintrea/mytetra_db_mcold/master/base/1500790473rdugh0q9he/text.html на raw.githubusercontent.com

import wx

 

class MyForm(wx.Frame):

 

def __init__(self):

wx.Frame.__init__(self, None, wx.ID_ANY, 'Image Extractor')

 

# Add a panel so it looks the correct on all platforms

self.panel = wx.Panel(self, wx.ID_ANY)

 

ico = wx.Icon('py.ico', wx.BITMAP_TYPE_ICO)

self.SetIcon(ico)

 

 

# Run the program

if __name__ == '__main__':

app = wx.PySimpleApp()

frame = MyForm().Show()

app.MainLoop()

The final way I would do this may be the best. In it, I take an icon or image and turn it into a python file using wx’s img2py utility. Why might this be the best? Because by embedding the image file in a python file, you simplify the process of distributing your application with py2exe. At least, that’s been my experience.

On my PC, the img2py utility can be found here:

C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\tools>

Adjust as needed for your setup. Open a command window and navigate to this directory. Then type the following command:

python img2py.py -i path/to/your/icon.ico myIcon.py

The first argument to img2py.py is the -i, which tells the utility that you’re embedding an icon. Next is the path to the icon file. Finally, you give the name of the file that you want img2py to create (i.e. embed the icon into). Now, copy the python file you just created over to the folder that contains your wxPython script so it can import it (or you can just copy the code out of the Python file into the text of the application you’re creating).

I’m going to import it for this example. To get the icon, you call the getIcon() method of the icon file I imported. Check out the code to see what I’m doing:

import wx

import myIcon

 

class MyForm(wx.Frame):

 

def __init__(self):

wx.Frame.__init__(self, None, wx.ID_ANY, 'Image Extractor')

 

# Add a panel so it looks the correct on all platforms

self.panel = wx.Panel(self, wx.ID_ANY)

 

ico = myIcon.getIcon()

self.SetIcon(ico)

 

 

# Run the program

if __name__ == '__main__':

app = wx.PySimpleApp()

frame = MyForm().Show()

app.MainLoop()

Hopefully this tutorial has helped you learn how to use your icon in your application. Remember, you can use these techniques for any image you want to insert; not just for the title bar icon, but for any static image you’d use in your application, such as a taskbar icon or a toolbar icon. Good luck!

Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования