''' 20210923 R. Dawes New features added in this version: I got tired of squinting to read the tiny letters and numbers in the previous versions, so I now increase the font size to 20 ''' import tkinter as tk from tkinter import font # gives access to the font control import sys window = tk.Tk() window.title("Compare two numbers") window.geometry("1200x800") # reset the default font size window.defaultFont = font.nametofont("TkDefaultFont") # the "window" object does not initially have a specified font, so we # give it one, using the standard font that tkinter uses. Now that "window" # has a font we can modify it window.defaultFont.configure(size=20) # This changes the font size for all Labels and Buttons. We will need to handle # Entry and Text widgets when we create them. 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, font=(None,20)) # The "font=(None,20)" argument means "Don't change the font, but change # the size to 20". If we wanted to use a special font we would put the name # of the font in place of "None" 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, font=(None,20)) #add a text box to show output text_1 = tk.Text(window,height = 10, width = 30, font=(None,20)) #add a button - a clickable object #add a function to react to button_1 def button_1_clicked(): try: x = float(entry_1.get()) except ValueError: x = None try: y = float(entry_2.get()) except ValueError: y = None text_1.delete(1.0, tk.END) if (x == None) or (y == None): text_1.insert(tk.END, "Invalid Input") else: 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 = 7) window.mainloop()