Convert an image file to a. py file

Source: Internet
Author: User

Recently, I wrote a script using wxpython. To set an icon file for the form, a separate ICO file is required, which affects the appearance of the image, in addition, it is cumbersome to package Icon files together during packaging. At this time, we can see that the wxpython file has a tool img2py. py.

This tool can convert the icon file into a. py file, which stores the binary information of the icon file.

The usage is as follows:

Python c: \ python27 \ Lib \ Site-packages \ wx-3.0-msw \ wx \ tools \ img2py. py-N = targetname-I ico. ICO

-N = targetname indicates the name of the referenced object in the converted. py file.

The generated. py file code is as follows:

  

#----------------------------------------------------------------------# This file was generated by C:\Python27\Lib\site-packages\wx-3.0-msw\wx\tools\img2py.py#from wx.lib.embeddedimage import PyEmbeddedImage_dormico = PyEmbeddedImage(    "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABHNCSVQICAgIfAhkiAAAAnhJ"    "REFUWIXFl6Fv4zAYxV+6SheQuxkaDBgEFNw0axoIKAg4EHDgYGD+jMLBwoIDAQOBBQcKAwMG"    "hqZMI500MOhj3V1A2AYqR3HipG7W6z0pkuPE/j1//uw4ljU6wemXz284ol7//LVkeXRsOABl"    "wGNZiG9icM5RFiUAYFNsAGDnfb2uq75et/q1UsxUBjjnmM/nA8c0XJUB6bbp8BBiLgPnXKm7"    "uDx/e7h/tMa6BkEQKGEjDgGwDeXd7R2iKAKlVLmkhBDaizhE6VOqMlB/uCk2oJSCOASUUtiO"    "jTRNO+G+71dtsyxrQYQQndHRRkCOel84APi+3zKhG7nUSBbqmTwEHl2/KCbq78kp7DXQ1D7w"    "WSzw49sp4ptYawIAvKkHf+qjKW0OANgPPv0ElE8I5y+w3RnK53llIssyCCEQ/4y1U6GNQF+2"    "6+Bk/Bt+uAKhHOwqwiRcK/1RSuFNvdZS7DSwL5x/T0AoBznj8CY21suJrluttEn4EXhyzar3"    "ZPgppeCc9+dAXSZwSl4x8XfDhRDI8xxCCPMcMIPHRnAZgSAI+nOg7u6Q8L5dsDcCTbj3dRg8"    "SZL9DdS1WCwQTNag9tMgeBRFZgbqq6AuSimYyxCG4SD4oCloGpAGuZMYw2ezmdKP7djDDDCX"    "wbva7mKccyP4crmsgH1fQqDnW1AZONsC0zRFmqZG8PXzGmVR7oQDBhHQ6VBwoGMnzPNce7KR"    "6oJnt+02xCEQhcGJSK4C5rKda7epj5yoWznAOVdOMF3Z23XK6Xq/a5lrp0CZv0LbDgL969tU"    "lYF/8T9golH9R/FYYi6rypY1OqluLi7Pj/aj+nD/aLUM/A+9A8ZICf9m/ywyAAAAAElFTkSu"    "QmCC")

When you need this icon, you only need to reference this. py file. The reference method is as follows:

from dormico import _dormicoself.SetIcon(_dormico.GetIcon())

OK. Solve the problem.

  

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.