# tkinter example with labels and buttons
from tkinter import *
# get factory function for a new font
# not sure why we have to import this separately 
from tkinter.font import Font

# function called by pushing the button
def whatButtonDoes():
    print("I like the pretty flower!")

# builds the GUI
def main():
    # define new window
    root = Tk()
    root.title("GUI window")
    root.geometry("260x360")

    # allows the contents of the window to be structured
    frame = Frame(root)
    frame.grid()

    # now get some stuff we'll need for components
    # get a bigger font. Helvetica is a common sans-serif font
    # people like sans-serif for computer interfaces
    big = Font(family="Helvetica",size=16)

    # reads in a picture
    # has to be in file in same folder, some image types do
    # not work (including jpg and tif)
    flowerPic = PhotoImage(file="Rhododendrum.gif")

    
    # puts the picture onto a label
    pic = Label(frame,image=flowerPic)
    pic.grid(row=0,column=0,rowspan=4,columnspan=3)
    # puts picture covering 4x3 grid

    # a label with text on it
    label = Label(frame,text="Rhododendrum",font=big)
    # figure out where it goes in window
    # starts in grid cell (0,0) and fills up one row and 3 columns
    label.grid(row=0,column=0,rowspan=1,columnspan=3)

    # a button that runs function whatButtonDoes
    like = Button(frame,text="Like!",font=big,\
                  command=whatButtonDoes)
    # starts in grid cell (4,2) and fills up one row and one column
    like.grid(row=4,column=2,rowspan=1,columnspan=1)

    # bring up the window
    root.mainloop()
    print("window is closed")

main()
    
