Skip to content

ValueError: Invalid Windows resource specifier - import a png #477

Closed Answered by xstu25
xstu25 asked this question in Q&A
Discussion options

You must be logged in to vote

I resolve my problem like this:
I add this code:

import sys, os
def resource_path(relative_path):
    """ Get the absolute path to the resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

Then I rename in my script all my image:

open('folder/my-file.png') ------> open(resource_path('folder/my-file.png'))

In my exemple:
image1 = customtkinter.CTkImage(Image.open(resource_path("rs/facebook.png")).resize((50, 50)), size=(50, 50))

Then I add the "folder" contain all my im…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by brentvollebregt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant