'How to open a python application by double-clicking a file from which it is the default application?

I made my python application the default application for the .txt extension using the Inno Setup. But I have two problems running the application by double-clicking a .txt file. The first problem is that the application uses a .ico image, and when I open the application by double-clicking a file, it searches for the image in the .txt file directory, not in the application directory. This is how I import the image:

`

import tkinter as tk
import os
import sys

app_folder = os.path.abspath(".")


def resource_path(relative):
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS, relative)
    return os.path.join(relative)


class App:
    def __init__(self, parent):
        parent.iconbitmap(resource_path(f'{app_folder}\\images\\logo.ico'))
        parent.geometry("1320x900")


if __name__ == "__main__":

    root = tk.Tk()
    app = App(root)
    root.mainloop()

`

This is the error:

_tkinter.TclError: bitmap "C:\Users\Filipe\Desktop\images\logo.ico" not defined.

How can I make the application search for the logo in the application installation folder?

The second question is how to import the double-clicked .txt file into the application? I think that I should call a function when the application is started by double-clicking a .txt file, but I have no idea about how to trigger this function. Any idea is welcome. ps: I'm using pyinstaller to bundle the application in a .exe file.



Sources

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

Source: Stack Overflow

Solution Source