diff --git a/main.py b/main.py index d4fb2b6..4da2979 100644 --- a/main.py +++ b/main.py @@ -1,158 +1,167 @@ +import sys from tkinter import * from tkinter.filedialog import askopenfilename, asksaveasfile import threading import time '''from ctypes import * - sum = CDLL('/home/manjunath/libsum.so') #UTF-8 to UNICODE sum.our_function.argtypes = [c_int, c_char_p] sum.our_function.restype = c_char_p ''' +def exit_editor(): + root.destroy() + + def about(): - filewin = Toplevel(root) - string = "This is a small text editor built using Tkinter a python which supports GUI programming\n" - string += "This text editor unlike many others supports many functions like giving suggestions based on your previous data \n" - string += "Small, easy to use and works like the future of text editors \n" - button = Label(filewin,text=string) - button.pack() + filewin = Toplevel(root) + string = "This is a small text editor built using Tkinter a python which supports GUI programming\n" + string += "This text editor unlike many others supports many functions like giving suggestions based on your previous data \n" + string += "Small, easy to use and works like the future of text editors \n" + button = Label(filewin,text=string) + button.pack() def open_file(): - global text,save_file_id - open_file_loc=askopenfilename() - open_file=open(open_file_loc,'r') - text.delete(1.0,END) - text.insert(END,open_file.read()) - save_file_id=open_file_loc + global text,save_file_id + open_file_loc=askopenfilename() + try: + open_file=open(open_file_loc,'r') + except FileNotFoundError: + return + text.delete(1.0,END) + text.insert(END,open_file.read()) + save_file_id=open_file_loc def save_as_file(): - global text,save_file_id - name=asksaveasfile(mode='w',defaultextension=".txt") - text2save=str(text.get(0.0,END)) - name.write(text2save) - name=str(name)[(str(name).find("name='")+6):str(name).find("'",(str(name).find("name='")+6))] - save_file_id=name + global text,save_file_id + name=asksaveasfile(mode='w',defaultextension=".txt") + text2save=str(text.get(0.0,END)) + try: + name.write(text2save) + except AttributeError: + return + name=str(name)[(str(name).find("name='")+6):str(name).find("'",(str(name).find("name='")+6))] + save_file_id=name def save_file(): - global text,save_file_id - if save_file_id=="": - save_as_file() - else: - with open(save_file_id,'w') as f: - f.write(text.get(0.0,END)) + global text,save_file_id + if save_file_id=="": + save_as_file() + else: + with open(save_file_id,'w') as f: + f.write(text.get(0.0,END)) def New_file(): - text.delete(1.0, END) - save_file_id = ' ' + text.delete(1.0, END) + save_file_id = ' ' def find_destroy(): - text.tag_remove(keyword,0.0,END) - search_box.destroy() - label1.destroy() - button1.destroy() - button2.destroy() + search_box.destroy() + label1.destroy() + button1.destroy() + button2.destroy() def find_button(): - global search_box,label1,button1,button2 - label1 = Label(text=" ") - label1.pack(side=LEFT) - search_box = Text(root,height=1, width=20) - search_box.pack(side=LEFT) - button1 = Button(root,text="find",command = Find) - button1.pack(side=LEFT) - button2 = Button(root,text="X",command = find_destroy) - button2.pack(side=LEFT) - + global search_box,label1,button1,button2 + label1 = Label(text=" ") + label1.pack(side=LEFT) + search_box = Text(root,height=1, width=20) + search_box.pack(side=LEFT) + button1 = Button(root,text="find",command = Find) + button1.pack(side=LEFT) + button2 = Button(root,text="X",command = find_destroy) + button2.pack(side=LEFT) + def Find(): - global keyword - keyword = search_box.get(0.0,END) - text_box = text.get(0.0,END) - text.tag_config(keyword,background='lightblue') - i = j = i_p = 0 - row = 1 - n = 0 - while i < len(text_box): - if (text_box[i] == keyword[j]): - i_p = i - n - while (text_box[i] == keyword[j]) and (j