import tkinter as tk
from functools import partial
#from builtins import None
Font_tuple = ("Comic Sans MS", 10, "bold")
def button_click(display9_value,V, R1, R2):
#display = tk.Label(root, text="Calculating",fg = "Dark Green").place(x = 165, y = 220)
X = V.get()
Y = R1.get()
Z = R2.get()
Voltage = (float(X)*float(Z))/(float(Y)+float(Z))
if ((Voltage is None) or (X is None) or (Y is None) or (Z is None)):
display = tk.Label(root, text="Calculation Error",fg = "Red").place(x = 165, y = 220)
else:
display = tk.Label(root, text="Calculation Successful",fg = "Dark Green").place(x = 165, y = 220)
display9_value.config(text="%f Volts" %Voltage)
voltage = None
X = None
Y = None
Z = None
return
root = tk.Tk()
root.geometry("525x280")
R1 = tk.StringVar()
R2 = tk.StringVar()
V = tk.StringVar()
VR2 = tk.StringVar()
logo1 = tk.PhotoImage(file="way2know.gif")
display = tk.Label(root, image=logo1).place(x = 455, y = 190)
logo = tk.PhotoImage(file="VR-image.gif")
display = tk.Label(root, image=logo).place(x = 320, y = 25)
display = tk.Label(root, text="Voltage with Resistive Divider", fg = "Blue",font = Font_tuple).place(x = 40, y = 20)
display1 = tk.Label(root, text="Resistor - R1").place(x = 40, y = 60)
display2 = tk.Entry(root,textvariable=R1).place(x = 175, y = 60)
display3 = tk.Label(root, text="Resistor - R2").place(x = 40, y = 100)
display4 = tk.Entry(root,textvariable=R2).place(x = 175, y = 100)
display5 = tk.Label(root, text="Voltage Rail - +V").place(x = 40, y = 140)
display6 = tk.Entry(root,textvariable=V).place(x = 175, y = 140)
display7 = tk.Label(root, text="Voltage across R2 (VR2)")
display7.place(x = 40, y = 180)
#display8 = tk.Entry(root,textvariable=VR2)
#display8.place(x = 175, y = 180)
display9 = tk.Label(root, text="To be calculated",fg = "Blue")
display9.place(x = 175, y = 180)
button_click = partial(button_click, display9, V, R1, R2)
display = tk.Button(root,text = "Calculate", command=button_click).place(x = 40,y = 220)
root.mainloop()
Below is the output screen for the above program:
0 Comments