Minimum and Maximum of 3 input numbers using tkinter

 import tkinter as tk

root=tk.Tk()

root.title("Maximum and Minumum")

root.geometry('640x480+300+300')

root.resizable(False, False)

title = tk.Label(

 root,

 text='ABC',

 font=('Timesnewroman 18 bold'),

 bg='green',

 fg='#AB1' )

num1=tk.DoubleVar()

num2=tk.DoubleVar()

num3=tk.DoubleVar()

num1_label = tk.Label(root, text='Number1: ')

num1_inp = tk.Entry(root, textvariable=num1)

num2_label = tk.Label(root, text='Number2: ')

num2_inp = tk.Entry(root, textvariable=num2)

num3_label = tk.Label(root, text='Number3: ')

num3_inp = tk.Entry(root, textvariable=num3)

max_btn = tk.Button(root, text=' max ')

min_btn = tk.Button(root, text=' min ')

output_var = tk.StringVar(value='')

output_line = tk.Label(

 root,

 textvariable=output_var,

 anchor='sw',

 justify='center' )

title.grid()

num1_label.grid()

num1_inp.grid()

num2_label.grid()

num2_inp.grid()

num3_label.grid(row=10,column=4)

num3_inp.grid(row=10,column=5)

max_btn.grid(row=99,column=0)

min_btn.grid(row=99,column=1)

output_line.grid(row=100, columnspan=2)

root.columnconfigure(1, weight=1)

root.rowconfigure(99, weight=2)

root.rowconfigure(100, weight=1)

def on_max_submit():

 """To be run when the user submits the form"""

 val1=num1.get()

 val2=num2.get()

 val3=num3.get()

 if(val1>val2):

 if(val1>val3):

 max=val1

else:

 max=val3

 elif(val2>val3):

 if(val2>val1):

 max=val2

else:

 max=val1

 elif(val3>val1):

 if(val3>val2):

 max=val3

else:

 max=val2 

 message = f'maximum is , {max}.\n'

 output_var.set(message)

def on_min_submit():

 """To be run when the user submits the form"""

 val1=num1.get()

 val2=num2.get()

 val3=num3.get()

 if(val1<val2):

 if(val1<val3):

 min=val1

else:

 min=val3

 elif(val2<val3):

 if(val2<val1):

 min=val2

else:

 min=val1

 elif(val3<val1):

 if(val3<val2):

 min=val3

else:

 min=val2 

 message = 'Minimum is ', {min}

 output_var.set(message)

max_btn.configure(command=on_max_submit)

min_btn.configure(command=on_min_submit)

root.mainloop()

Comments

Popular posts from this blog

Diagonal Relationship between Beryllium and Aluminium || Relation between Beryllium and Aluminium

QUANTUM NUMBERS (Principal, Azimuthal, Magnetic and Spin)

Distinction between Electromagnetic Waves and Matter Waves

Math question

What do you mean by a precipitation reaction? Explain by giving examples.