from tkinter import *
import requests

window = Tk()
window.geometry('700x550')
window.title('ASCII Art Generator')
window.grid_columnconfigure(0, weight=1)
window.configure(background='#ccccb3')

welcome_label = Label(window, text='Enter sentence to convert to ASCII art!', font=('Comic Sans MS', 12), fg='black',
                      bg='#ccccb3')
welcome_label.grid(row=0, column=0, padx=25, pady=5, sticky='N')

text_input = Entry(justify=CENTER, fg='black', font='TimesNewRoman')
text_input.grid(row=1, column=0, sticky='WE', padx='10')

text_widget1 = Text(state=DISABLED)
text_widget1.grid(row=3, column=0, sticky='N', padx=15, pady=5)

credits_label = Label(window, text='ASCII Art generated by artii.herokuapp.com', bg='#ccccb3')
credits_label.grid(row=4, column=0, sticky='S', padx=15, pady=10)


def download_art():
    if text_input.get():
        user_input = text_input.get()
        payload = {'text': user_input}
        response = requests.get('http://artii.herokuapp.com/make', params=payload)
        text_response = response.text
    else:
        text_response = 'Text input cannot be empty'

    text_widget = Text(wrap=NONE)
    text_widget.insert(END, text_response)
    text_widget.grid(row=3, column=0, sticky='WE', padx=15, pady=5)


download_btn = Button(text='Convert to Art', command=download_art)
download_btn.grid(row=2, column=0, padx=15, pady=10, sticky='N')


if __name__ == '__main__':
    window.mainloop()