How do I create a function that takes the 3 variables and displays the highest value when the Calculate button is pressed?????
Below is my current code. I'm creating a GUI for the User to input 3 different readings. If the input is negative or string, my program is to return an invalid entry, if all 3 different readings are correct, once the calculate button is clicked the highest value is then displayed in the answer. answer = Label(frame, text='')
answer.grid(column=1, row=6)
The USER doesn't need to store the data just display the highest entry?????
Thank you
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
root = Tk()
root.title('Reading Total')
root.geometry('700x200')
############################# Frames ################################
frame = ttk.Frame(root, padding='3 3 12 12')
frame.grid(column=0, row=0, sticky=(N, W, E, S))
frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
frame.columnconfigure(2, weight=1)
frame.rowconfigure(0, weight=1)
frame.rowconfigure(1, weight=1)
frame.rowconfigure(2, weight=1)
frame.rowconfigure(3, weight=1)
frame.rowconfigure(4, weight=1)
############################# Variables ################################
Item1 = StringVar()
Item2 = StringVar()
Item3 = StringVar()
## Do I need to create a Variable to store the values???
############################# Entry ################################
o_entry=ttk.Entry(frame, width=7, textvariable=Item1)
o_entry.grid(column=1, row=1, sticky=(W, E))
sul_entry=ttk.Entry(frame, width=7, textvariable=Item2)
sul_entry.grid(column=1, row=2, sticky=(W, E))
particles_entry=ttk.Entry(frame, width=7, textvariable=Item3)
particles_entry.grid(column=1, row=3, sticky=(W, E))
############################# Labels ################################
o_label = ttk.Label(frame, text='Item1:')
o_label.grid(column=0, row=1, sticky = E)
s_label = ttk.Label(frame, text='Item2:')
s_label.grid(column=0, row=2, sticky=E)
p_label = ttk.Label(frame, text='Item3:')
p_label.grid(column=0, row=3, sticky=E)
############################# Function ################################
def number_1():
try:
O = float(Item1.get())
T = (50 * O)/5
Ta = ("%0.2f" % (T))
answer["text"]= 'Reading:', str(Ta)
assert O > 0
except AssertionError:
answer.config(text="Invalid Entry")
except ValueError:
answer.config(text="Invalid Entry")
def number_2():
try:
S = float(Item2.get())
T1 = (50 * S)/20
Tb = ("%0.2f" % (T1))
answer["text"]= 'Reading:', str(Tb)
assert S > 0
except AssertionError:
answer.config(text="Invalid Entry")
except ValueError:
answer.config(text="Invalid Entry")
def number_3():
try:
P = float(Item3.get())
T2 = (60 * P)/20
Tc = ("%0.2f" % (T2))
answer["text"]= 'Reading:', str(Tc)
assert P > 0
except AssertionError:
answer.config(text="Invalid Entry")
except ValueError:
answer.config(text="Invalid Entry")
############################# Buttons ################################
g_button = ttk.Button(frame, text='Calculate', **command =) # Need to create a function that calls all 3 functions**
g_button.grid(column=1, row=4, sticky=N)
############################# End ################################
answer = Label(frame, text='')
answer.grid(column=1, row=6)
root.columnconfigure(0, weight = 1)
root.rowconfigure(0, weight = 1)
root.mainloop()