from tkinter import *
import file_work


def clear_text():
    text_window.delete(1.0, END)

def get_text():
    return text_window.get(1.0, END)

def read_text():
    clear_text()
    text_window.insert(1.0, file_work.read())

def search_text():                      # не працює !!!
    inp = text_window.get(1.0, END)
    info = file_work.search(inp)
    clear_text()
    text_window.insert(1.0, info)

def add_text():
    inp = text_window.get(1.0, END)
    file_work.add(inp[:-1])             #видаляєм "\n" (останній символ)
    read_text()

#def remove_text():
#    inp = text_window.get(1.0, END)


root = Tk()
root.title("manager")
root.geometry('800x600')
root.config(background='grey')

text_window = Text(root, font=("Courier New", 12, 'bold'), width=55, height=29, bd=5, bg='powder blue')
text_window.place(y=15, x=200)

read = Button(text="Read", height=3, width=15, command=read_text)
read.place(y=15, x=20)

clear = Button(text="Clear Window", height=3, width=15, command=clear_text)
clear.place(y=115, x=20)

search = Button(text="Search", height=3, width=15, command=search_text)
search.place(y=215, x=20)

add = Button(text="Add", height=3, width=15, command=add_text)
add.place(y=315, x=20)

#remove = Button(text="Remove", height=3, width=15, command=remove_text)
#remove.place(y=315, x=20)

label = Label()
label.pack()

root.mainloop()