I have created a program that can edit the contents of a text file. Assume that my program looks something like this:
from tkinter import *
from tkinter import filedialog
root = Tk()
def open_file():
file_to_open = filedialog.askopenfilename(initialdir="C:/" , filetypes=(("All files" , "*.*"),))
if file_to_open != "":
file = open(file_to_open , 'r')
content_in_file = file.read()
file.close()
text.delete('1.0' , END)
text.insert('1.0' , content_in_file)
def save_file():
path = filedialog.asksaveasfilename(initialdir="C:/" , filetypes=(("All files" , ""),))
if path != "":
file = open(path , 'w')
file.write(text.get('1.0' , 'end-1c'))
file.close()
text = Text(root , width = 65 , height = 20 , font = "consolas 14")
text.pack()
open_button = Button(root , text = "Open" , command = open_file)
open_button.pack()
save_button = Button(root , text = "Save" , command = save_file)
save_button.pack(pady=20)
mainloop()
The problem here is that when I click on a text file in my file explorer, it opens with the default windows notepad instead of opening with my program.
What I want is that all the text files should open with my program instead of opening with the default windows Notepad.
Here's what I did (in order):
After completing the following steps, I tried opening my text file, but it says:
I tried converting my python program into an exe file (using pyinstaller) and then following the steps above, but when I open the text file I get an other error:
Is there anything wrong with my code or the steps I followed?
I would really appreciate it if anyone could guide me through how I can open a text file with my program.






.exeand the error?