simple dialog based application (ohms law) using Raspberry PI and python
Rate this article
0 out of 5
In this tutorial we will show you simple dialog based application (ohms law) using Raspberry PI and python

 


from Tkinter import *
fields = ('VOLTAGE', 'CURRENT', 'RESISTANCE')

def calculate(entries):
   
   v = float(entries['VOLTAGE'].get())
   i =  float(entries['CURRENT'].get())
   
   r = (v/i)
   r = ("%8.2f" % r).strip()
   entries['RESISTANCE'].delete(0,END)
   entries['RESISTANCE'].insert(0, r )
   print("RESISTANCE: %f" % r)



def clear(entries):
entries['RESISTANCE'].delete(0,END)
entries['VOLTAGE'].delete(0,END)
entries['CURRENT'].delete(0,END)

def makeform(root, fields):
   entries = {}
   for field in fields:
      row = Frame(root)
      lab = Label(row, width=22, text=field+": ", anchor='w')
      ent = Entry(row)
      ent.insert(0,"0")
      row.pack(side=TOP, fill=X, padx=5, pady=5)
      lab.pack(side=LEFT)
      ent.pack(side=RIGHT, expand=YES, fill=X)
      entries[field] = ent
   return entries

if __name__ == '__main__':
   root = Tk()
   ents = makeform(root, fields)
   root.bind('<Return>', (lambda event, e=ents: fetch(e)))   
   b1 = Button(root, text=' CALCULATE ',
          command=(lambda e=ents: calculate(e)))
   b1.pack(side=LEFT, padx=5, pady=5)
   b2 = Button(root, text=' CLEAR ',
          command=(lambda e=ents: clear(e)))
   b2.pack(side=LEFT, padx=5, pady=5)
   b3 = Button(root, text='QUIT ', command=root.quit)
   b3.pack(side=LEFT, padx=5, pady=5)
   root.mainloop()



source code

   
Messages
Posted:
Post Your Comments
Name (Max 50 Chars)
Comments
   Design  HTML

Copyright © KTS Infotech 2000-2023. Site Developed Using KTS WebCloud
Reach Us on facebookWatch Video Tutorials on YouTube Channel TekTipsNavigate to KTS Technology Blog