import tkinter as tk
from PIL import ImageTk, Image
import sys

root = tk.Tk()                  # Root widget
root.title("My first GUI!")

canvas = tk.Canvas(             # Canvas widget
    root,
    width=1024,
    height=800,
    bg='white'
)
canvas.pack(fill=tk.BOTH, expand=1)

canvas.create_text(
    1024/2, 400,
    anchor=tk.CENTER,
    text='Curious Zelda is shocked!',
    font=('Arial',30,'bold italic'),
)

# Add your own images to the canvas!

image = Image.open("curious_zelda.jpg")
image = ImageTk.PhotoImage(image)
canvas.create_image(1024/2, 200, anchor=tk.CENTER, image=image)


# Create an event process to change the state of the canvas
def event_processor(event):
    print('Inside event processor')
    global canvas
    if str(event.char) == 'c':
        canvas.delete(tk.ALL)
        canvas.create_text(
            1024 / 2, 800/2,
            anchor=tk.CENTER,
            text='You\'ve cleared me!',
            font=('Arial', 30, 'bold italic'),
        )
    elif str(event.char) == 'q':
        sys.exit()


root.bind("<Key>", event_processor)
root.mainloop()

