diff --git a/Notepad.py b/Notepad.py index cbe1370..87a5bf3 100755 --- a/Notepad.py +++ b/Notepad.py @@ -1,4 +1,3 @@ -import tkinter import os from tkinter import * from tkinter.messagebox import * @@ -21,16 +20,11 @@ class Notepad: __file = None def __init__(self,**kwargs): - #initialization - - #set icon - try: - self.__root.wm_iconbitmap("Notepad.ico") #GOT TO FIX THIS ERROR (ICON) - except: - pass + #set icon + self.__icon() + #set window size (the default is 300x300) - try: self.__thisWidth = kwargs['width'] except KeyError: @@ -82,18 +76,22 @@ def __init__(self,**kwargs): self.__thisScrollBar.config(command=self.__thisTextArea.yview) self.__thisTextArea.config(yscrollcommand=self.__thisScrollBar.set) - + def __icon(self): + icon_path = os.path.join("Python-Notepad/assets/Notepad.ico") + if os.path.exists(icon_path): + self.__root.iconbitmap(icon_path) + else: + print(f"Icon file not found: {icon_path}") + def __quitApplication(self): self.__root.destroy() #exit() def __showAbout(self): showinfo("Notepad","Created by: Ferdinand Silva (http://ferdinandsilva.com)") - - def __openFile(self): - + + def __openFile(self): self.__file = askopenfilename(defaultextension=".txt",filetypes=[("All Files","*.*"),("Text Documents","*.txt")]) - if self.__file == "": #no file to open self.__file = None @@ -109,7 +107,6 @@ def __openFile(self): file.close() - def __newFile(self): self.__root.title("Untitled - Notepad") self.__file = None @@ -129,9 +126,7 @@ def __saveFile(self): file.write(self.__thisTextArea.get(1.0,END)) file.close() #change the window title - self.__root.title(os.path.basename(self.__file) + " - Notepad") - - + self.__root.title(os.path.basename(self.__file) + " - Notepad") else: file = open(self.__file,"w") file.write(self.__thisTextArea.get(1.0,END)) @@ -147,13 +142,9 @@ def __paste(self): self.__thisTextArea.event_generate("<>") def run(self): - #run main application self.__root.mainloop() - - - #run main application notepad = Notepad(width=600,height=400) notepad.run() diff --git a/assets/Notepad.ico b/assets/Notepad.ico new file mode 100644 index 0000000..a65235b Binary files /dev/null and b/assets/Notepad.ico differ