# Allison Obourn
# CS 115, Autumn 2021
# Lecture 34

# This program creates a GUI with a title on the first line, an instruction
# to type a guess and an input box for the user to type in on the second line
# and a button on the third. When the user clicks the button the program
# prints whether the number the user typed in the box is too high, too low
# or the right answer

# NOTE: This program does no work correctly yet and is not an example of good
#       style! We will fix it tomorrow.

from ECGUI import *
from random import *

# generates a random number, prints it to the console and compares it against
# the user's guess. Outputs a "too high", "too low" or win message to the GUI
# depending on how the user's answer compares to the correct answer
def process_guess():
    answer = randint(1, 100)
    print(answer)
    user_guess = int(guess.get())
    if user_guess == answer:
        change_label(hint, "You win!")
    elif user_guess < answer:
        change_label(hint, "Too low!")
    else:
        change_label(hint, "Too high!")


window = make_window("Guessing Game")
title = add_label(window, "CS 115 Guessing Game", padding_bottom=20)

# we put all the contents of the first line in a frame so that it would
# line up horizontally
line1 = add_frame(window, padding_bottom=10)
instructions = add_label(line1, "Your guess: ", side="left")
guess = add_entry_box(line1)

submit = add_button(window, "guess!")
submit['command'] = process_guess
hint = add_label(window, "")
