from tkinter import * from tkinter.filedialog import askopenfilename, asksaveasfile import threading import time def about(): filewin = Toplevel(root) string = "Hakkımda kısmı\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 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 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)) def New_file(): text.delete(1.0, END) save_file_id = ' ' def undo(): global undo_list,text text = undo_list.pop() def heapify(match_list, n, i): largest = i # Initialize largest as root l = 2 * i + 1 # left = 2*i + 1 r = 2 * i + 2 # right = 2*i + 2 if l < n and match_list[i] < match_list[l]: largest = l if r < n and match_list[largest] < match_list[r]: largest = r # Change root, if needed if largest != i: match_list[i],match_list[largest] = match_list[largest],match_list[i] # swap heapify(match_list, n, largest) def heapSort(match_list): n = len(match_list) # Build a maxheap. for i in range(n, -1, -1): heapify(match_list, n, i) # One by one extract elements for i in range(n-1, 0, -1): match_list[i], match_list[0] = match_list[0], match_list[i] # swap heapify(match_list, i, 0) def drop_suggest(*args): var_value = var.get() global Text txt = '' i = len(txt) - 1 for i in text_list: txt += i + ' ' txt += var.get() text.delete(0.0, END) text.insert(0.0,txt) w.destroy() def suggest(): global text, var, text_list, w text_list = text.get(0.0,END).split(" ") last_word = text_list.pop() last_word = last_word[:-1] fp = open("dictionary.txt","a+") for i in text_list: fp.write(i+' ') match_list = [] fp.seek(0) for i in fp.read().split(" "): if '\n' in i: v = i.split("\n") for k in v: if k is not '': match_list.append(k) continue if last_word in i: match_list.append(i) match_list = list(set(match_list)) var = StringVar(root) if len(match_list) != 0: heapSort(match_list) var.set(match_list[0]) var.trace('w',drop_suggest) w = OptionMenu(root,var,*match_list) w.pack() fp.close() def drop_style(*args): txt = text.get(0.0,END) text.delete(0.0,END) text.configure(font = (var.get(), text_size)) text.insert(0.0,txt) w.destroy() def font_style(): global text, var, w var = StringVar(root) var.set(text_style) match_list = ["Times New Roman", "Helvetica", "Ariel", "Courier","Symbol","monospace"] var.trace('w', drop_style) w = OptionMenu(root, var, *match_list) w.pack() def drop_size(*args): txt = text.get(0.0,END) text.delete(0.0,END) text.configure(font = (text_style, var.get())) text.insert(0.0,txt) w.destroy() def font_size(): global var, w var = StringVar(root) var.set(text_size) match_list = [8, 10, 11, 12, 14] var.trace('w', drop_size) w = OptionMenu(root, var, *match_list) w.pack() root = Tk() root.title("Notepad") text=Text(root, width=200, undo=True) text_size = 11 text_style = "Times New Roman" text.configure(font=(text_style, text_size)) text.pack() save_file_id="" menubar = Menu(root) filemenu = Menu(menubar, tearoff = 0) menubar.add_cascade(label = "Dosya", menu = filemenu) filemenu.add_command(label="Yeni", command = New_file) filemenu.add_command(label = "Aç", command = open_file) filemenu.add_command(label = "Kaydet", command = save_file) filemenu.add_command(label = "Farklı kaydet...", command = save_as_file) filemenu.add_command(label = "Çıkış", command = root.quit) Editmenu = Menu(menubar, tearoff=0) menubar.add_cascade(label = "Düzenle", menu = Editmenu) Editmenu.add_command(label = "Font stili", command = font_style) Editmenu.add_command(label = "Font boyutu", command = font_size) helpmenu = Menu(menubar, tearoff=0) menubar.add_cascade(label = "Yardım?", menu = helpmenu) helpmenu.add_command(label = "Hakkında...", command = about) root.config(menu = menubar) root.mainloop()