# flower slide show flips between three images
from tkinter import *
from tkinter.font import Font

# function called by pushing the button
def whatButtonDoes():
    global labelText # need to declare this global
    # because this function will change its value
    
    if labelText == "Rhododendrum":
        pic.config(image=cami) # change the picture
        labelText = "Camellia" # change the text
        label.config(text=labelText)
    elif labelText == "Camellia":
        pic.config(image=colum)
        labelText = "Columbine"
        label.config(text=labelText)
    else: # must be Columbine
        pic.config(image=rhodo)
        labelText = "Rhododendrum"
        label.config(text=labelText)

# builds the GUI
def main():
    # all these variables need to be used in the callback
    # function
    global pic
    global cami
    global rhodo
    global colum
    global label
    global labelText
    
    # define new window
    root = Tk()
    root.title("GUI window")
    root.geometry("280x400")

    # 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 pictures
    # has to be in file in same folder, some image types do
    # not work (including jpg and tif)
    rhodo = PhotoImage(file="Rhododendrum.gif")
    cami = PhotoImage(file="Camellia.gif")
    colum = PhotoImage(file="Columbine.gif")

    # puts a picture onto a label
    pic = Label(frame,image=rhodo)
    pic.grid(row=2,column=0,rowspan=3,columnspan=3)
    # puts picture covering 4x3 grid

    # a label with text on it
    labelText = "Rhododendrum"
    label = Label(frame,text=labelText,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
    next = Button(frame,text="next",font=big,\
                  command=whatButtonDoes)
    # starts in grid cell (4,2) and fills up one row and one column
    next.grid(row=5,column=2,rowspan=1,columnspan=1)

    # bring up the window
    root.mainloop()
    print("window is closed")

main()
    
