0

I am learning Tkinter in Python by building a simple Image viewer GUI based application with buttons to open the file explorer and load images by extracting their path.

Now, I wanted to use this Tkinter application as default application, which basically means when I click any image, my Tkinter application should open and show me the image. How can I do this?

  • [This](https://stackoverflow.com/q/7962157/7519434) may be of use assuming you're on Windows. Either use a batch file or compile to exe. Then use `sys.argv[1]` to get the file path. – Henry Jun 02 '23 at 20:46

1 Answers1

0

Assuming you're on Windows, this is just changing the file type association, which ultimately is a registry value change, though users usually don't need to make registry changes directly.

As described here, if you just want to do this on your computer, you can make this change in file explorer by right-clicking a file, selecting 'open with' and selecting your program and electing to make that program the default.
In Windows 10 and Windows 11, you can also use the default apps settings.

When users open files with associated file types, the file path will be passed to your application as an argument. Your application will need to read the arguments (in Python, from sys.argv) and take appropriate steps to 'open' the file -- whatever that means for your app.

sytech
  • 29,298
  • 3
  • 45
  • 86