''' 20210923 R. Dawes New features added in this version: We add an "Exit" button to the window so that we don't have to click on the "close window" button in the top corner We fix the problem of getting "8 > 10" as output. This problem occurs because tkinter Entry widgets always treat their input as strings ... and the string "8" comes after the string "10" in lexicographic (dictionary) order. To get the desired result we convert the input strings to numbers using the built-in "float()" function. But this causes a new problem: the information we add to a Text widget can ONLY be a string. So we have to convert the float values back to strings. ''' import tkinter as tk import sys # because we want to use sys.exit() to close the gui window = tk.Tk() window.title("Compare two numbers") window.geometry("1200x800") label_1 = tk.Label(window,text="Enter x in this box") #add an entry box to accept input entry_1 = tk.Entry(window, width = 10) label_2 = tk.Label(window,text="Enter y in this box") #add an entry box to accept input entry_2 = tk.Entry(window, width = 10) #add a text box to show output text_1 = tk.Text(window,height = 10, width = 30) #add a button - a clickable object #add a function to react to button_1 def button_1_clicked(): x = float(entry_1.get()) y = float(entry_2.get()) text_1.delete(1.0, tk.END) # clear the Text box if (x < y): text_1.insert(tk.END, str(x) + " < " + str(y)) elif (x > y): text_1.insert(tk.END, str(x) + " > " + str(y)) else: text_1.insert(tk.END, str(x) + " = " + str(y)) button_1 = tk.Button(window, text = "Compare Them", command = button_1_clicked) #add a button to end execution button_2 = tk.Button(window,text = "Exit", command = sys.exit) label_1.grid(row = 0, column = 0) entry_1.grid(row = 0, column = 1) label_2.grid(row = 1, column = 0) entry_2.grid(row = 1, column = 1) button_1.grid(row = 2, column = 0) text_1.grid(row = 2, column = 2) button_2.grid(row = 7, column = 10) # tkinter doesn't object if you try to put widgets in rows or columns far away # from everything else ... it just doesn't waste any space on empty rows or columns # This placement will look exactly the same as if we placed button_2 in row = 3, column = 3 window.mainloop()