Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a .exe for Python with good graphics?

I have a Python application and I decided to do a .exe to execute it.

This is the code that I use to do the .exe:

# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')


setup(
    options = {'py2exe': {'bundle_files': 1}},
    windows = [{'script': "SoundLog.py"}],
    zipfile = None,
    packages=[r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar", r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins"],
)

But when I run my application with the .exe, the graphics are quite different.

In the image bellow you can see the application running thought python at the left and running thought the .exe at the right. alt text

How can I make the .exe one be as good as the one that runs thought python?

like image 410
aF. Avatar asked May 13 '26 19:05

aF.


2 Answers

I assume you mean the visual style of the toolbar and buttons. You need to add a manifest file to the EXE file or as a separate file so that Windows applies the modern style of recent comctl32.dll versions.

Check out Using Windows XP Visual Styles With Controls on Windows Forms on MSDN. Read the relevant part about creating the ".exe.manifest" file.

A more py2exe-specific tutorial can be found over at the wxPython site. They explain how to use setup.py to include the necessary manifest file.

like image 89
AndiDog Avatar answered May 15 '26 08:05

AndiDog


The final setup that I mounted was this:

# -*- coding: cp1252 -*-
from distutils.core import setup
import py2exe, sys, os
from glob import glob

sys.argv.append('py2exe')


manifest = """
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
     type='win32'
     name='Microsoft.VC90.CRT'
     version='9.0.21022.8'
     processorArchitecture='*'
     publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         processorArchitecture="*"
         publicKeyToken="6595b64144ccf1df"
         language="*" />
    </dependentAssembly>
  </dependency>
</assembly>
"""

setup(
##    data_files = data_files,
    options = {'py2exe': {'bundle_files': 1}},
    windows = [{'script': "SoundLog.py", 'other_resources': [(24,1,manifest)]}],
    zipfile = None,
    packages=[r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Auxiliar", r"C:\Users\Public\SoundLog\Code\Código Python\SoundLog\Plugins"],
)

Thanks for the quick answers :)

like image 31
aF. Avatar answered May 15 '26 07:05

aF.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!