'Allocating external text, icon, and image files so that Python Script can function on multiple PCs?

I've been having this main issue in my code i've been trying to compile. I am trying to make a GUI-based application, utilizing the tkinter and pandas libraries.

The purpose of this code is to do some data science sorting, and that has been accomplished. However, on the tkinter/GUI side of things, the images I am trying to include in the tkinter application only work when the script main.py is executed in my PyCharm library. When I try to run the script on its own within its respective folder, I get multiple errors stating that client.ico, help.txt, HomeIcon.png, Mugi.png, and SMI.png don't exist because the path to the file is invalid.

Looking at my code, all of the times I reference images involve using the .iconbitmap and .open / .PhotoImage commands, with my references to the images only being referenced as far as the PyCharm project folder, such as the examples below:

##### This is a class for displaying a picture. Uses "root" to reference the frame/window it will be placed in.
class MakePicture():
    def __init__(self, root, lbl, xpos, ypos, picture):
        pic = Image.open(picture)
        mugi = ImageTk.PhotoImage(pic)
        lbl = Label(root, image=mugi)
        lbl.image = mugi
        lbl.place(relx=xpos, rely=ypos, anchor=CENTER)```

class Window():
    ##### Input an instance, desired width, height, window name, a title, and icon path.
    def __init__(self, root, xres, yres, title, icon):
        ##### SETTING UP THE WINDOW
        self.root = root
        self.root.title(title)
        self.root.iconbitmap(icon)
        w = xres
        h = yres
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        x = (ws / 2) - (w / 2)
        y = (hs / 2) - (h / 2)
        root.geometry('%dx%d+%d+%d' % (w, h, x, y))
        self.root.resizable(False, False)

Both of these classes specify the commands. The following examples of me summoning them is shown below:

    MakePicture(root, 1, 0.5, 0.5, "SMI.png")
    Window(root, 1000, 600, "MQTT Dashboard", "clienticon.ico")

As for the text file, I utilized the webbrowser.open command from the webbrowser library in order to open the help document help.txt whenever a button was pressed:

def help():
    def opentxt():
        webbrowser.open("help.txt")

    mugihelp = Toplevel()
    MakeLabel(mugihelp, 1, 0.5, 0.3, "Questions? Concerns?", "TNR", 20, 'black')
    MakeButton(mugihelp, 1, 0.5, 0.65, "Get Help!", opentxt)
    Window(mugihelp, 400, 200, "Dashboard", "clienticon.ico")
    mugihelp.mainloop()
    return None

I did not specify a path for ANY of these files, because I wanted this code to work on other Windows-based machines - this meant that I could not simply just copy paste the path to my folder on my personal windows machine. But this also means that my code will not work outside the PyCharm project i've placed it in.

I would appreciate any form of workaround for this problem. Any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source