The image that is going to be used is the next one:
The code is the next one:
from Tkinter import *
def calc_Re():
"""
Re : Reynolds Number
(Adimensional number used to determine
if a fluid flow is laminar or turbulent type)
Re = velocity * diameter / kinematic_viscosity
Re = v__val * d__val / nu_val
(row = 3, column = 1)
"""
if nu_val.get() == 0:
print "Kinematic viscosity must be greater than zero"
lab4.config(text="Nu = 0")
lab4.grid(row = 3, column = 1)
else:
v_ = v__val.get()
d_ = d__val.get()
nu = nu_val.get()
re_= v_ * d_ / nu
result = "Re = " + str(re_)
print "Re = {: f};(U = {: f}, D = {: f}, v = {: f})".format(re_, v_, d_, nu)
lab4.config(text=result)
lab4.grid(row = 3, column = 1)
root = Tk()
root.title("Reynolds (Re)")
img_01 = PhotoImage(file = "_Re_01_54x25.gif")
v__val = DoubleVar()
d__val = DoubleVar()
nu_val = DoubleVar()
lab1 = Label(root, text = "velo: U =").grid(row = 0, column = 0)
lab2 = Label(root, text = "diam: D =").grid(row = 1, column = 0)
lab3 = Label(root, text = "nu__: v =").grid(row = 2, column = 0)
lab4 = Label(root, text = " ")
ent1 = Entry(root, textvariable = v__val).grid(row = 0, column = 1)
ent2 = Entry(root, textvariable = d__val).grid(row = 1, column = 1)
ent3 = Entry(root, textvariable = nu_val).grid(row = 2, column = 1)
btn1 = Button(root, image = img_01, command = calc_Re).grid(row = 3, column = 0)
root.mainloop()
As you can see the "grid" system is used for the organization of everything.
The result for when you run the code is:
You can try the consistence of the definitions by seeing that the zero division is being controlled, the message in that situation would be "Nu = 0":
The rest is just a question of using valid values and see the results:
No comments:
Post a Comment