Skip to content

[Solved][Python] AttributeError: module ‘win32ctypes.pywin32.win32api’ has no attribute ‘error’

Last Updated on 2020-11-24 by Clay

Display Python code on the screen

Introduction

Today I used PyInstaller to package my Python program to execute file on Windows, I got an error message:

AttributeError: module 'win32ctypes.pywin32.win32api' has no attribute 'error'

After I searching some information on Internet, I found it is a common problem about icon picture of our GUI program. The icon need to use the .ico file, but I use a .png file.

This icon is on the computer desktop dock, not the icon on the program window.


Solution

The easiest way is to find a website on the Internet that can convert images to .ico, for example: https://image.online-convert.com/convert-to-ico

Or maybe you can use the pillow module in Python to convert the image format.

# -*- coding: utf-8 -*-
from PIL import Image


image = Image.open('pic/NightyTimer_Icon.png')
print(image.size)


Output:

(32, 32)

We can save it to .ico extension.

image.save('test.ico', sizes=[(32, 32)])


Dont’ forget to input the sizes argument, otherwise it may be inaccurate.


References


Read More

Tags:

Leave a ReplyCancel reply

Exit mobile version