-1

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()
vulcan
  • 1
  • Your functions, `def number_1():`, have to return a value. As it stands, they return `None`. Read [making-python-tkinter-label-widget-update](https://stackoverflow.com/questions/1918005) – stovfl May 17 '20 at 11:12

1 Answers1

0

Just create a function to call the three others functions:

def display_items():
    number_1()
    number_2()
    number_3()

And call it with button:

g_button = ttk.Button(frame, text='Calculate', command=display_items)
Alchimie
  • 426
  • 4
  • 12
  • I already tried this in my code prior to posting. I need to call a function where it displays the highest input value? Once all 3 StringVar have been added in the GUI the highest values is displayed ##answer = Label(frame, text='') answer.grid(column=1, row=6)## also if the value or input is correct an error is displayed in the same label ##answer = Label(frame, text='') answer.grid(column=1, row=6)## – vulcan May 17 '20 at 08:12
  • Need some help please – vulcan May 17 '20 at 10:10
  • If you mean display the max number use :max(Item1.get(), Item2.get(), Item3.get()). Tell me if you want something else. – Alchimie May 17 '20 at 10:37