Advertisement
AceScottie

RPM_calc.py

Jan 11th, 2020
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.96 KB | None | 0 0
  1. from tkinter import *
  2. from math import pi
  3. class RMP_mesure:
  4.     def __init__(self):
  5.         self.quit = False
  6.         self.root = Tk()
  7.         self.root.protocol("WM_DELETE_WINDOW", self.quitter)
  8.         self.root.title("RPM Converter")
  9.         self.root.geometry("250x100+100+100")
  10.         self.root.configure(bg="white")
  11.         self.output = None
  12.        
  13.     def calc(self, event, rd, rp):
  14.         try:
  15.             rd = float(rd.get())
  16.         except:
  17.             self.output.delete(0, END)
  18.             self.output.insert(0, "Please insert Radius as a floating point number")
  19.             self.output.configure(fg="red")
  20.         try:
  21.             rp = int(rp.get())
  22.         except:
  23.             self.output.delete(0, END)
  24.             self.output.insert(0, "Please insert RPM as a floating point number")
  25.             self.output.configure(fg="red")
  26.         rps = rp/60
  27.         c = 2*pi*rd
  28.         dis = c*rps
  29.         mps = dis/100
  30.         self.output.delete(0, END)
  31.         self.output.insert(0, "%s m/s"%str(mps)[0:str(mps).index(".")+3])
  32.         self.output.configure(fg="black")
  33.        
  34.     def run(self):
  35.         f1 = Frame(self.root, bg="white")
  36.         f1.pack(side=TOP, fill=X)
  37.        
  38.         f2 = Frame(self.root, bg="white")
  39.         f2.pack(side=TOP, fill=X)
  40.        
  41.         f3 = Frame(self.root, bg="white")
  42.         f3.pack(side=TOP, fill=X)
  43.        
  44.         f4 = Frame(self.root, bg="white")
  45.         f4.pack(side=TOP, fill=X)
  46.        
  47.         Label(f1, text="Radius(cm)", width=10, justify=RIGHT, anchor="e", bg="white").pack(side=LEFT)
  48.         rd = Entry(f1)
  49.         rd.pack(side=LEFT, fill=X)
  50.        
  51.         Label(f2, text="RPM", width=10, justify=RIGHT, anchor="e", bg="white").pack(side=LEFT)
  52.         rp = Entry(f2)
  53.         rp.pack(side=LEFT, fill=X)
  54.        
  55.         self.output = Entry(f3, bg="white", fg="black")
  56.         self.output.pack(fill=X, expand=1)
  57.        
  58.        
  59.         Button(f4, text="Calculate", bg="white", command=lambda e=Event(), rd=rd, rp=rp: self.calc(e, rd, rp)).pack(fill=X, expand=1)
  60.        
  61.         while not self.quit:
  62.             self.root.update()
  63.             self.root.update_idletasks()
  64.        
  65.     def quitter(self):
  66.         self.quit = True
  67.  
  68.  
  69. if __name__ == "__main__":
  70.     app = RMP_mesure()
  71.     try:
  72.         app.run()
  73.     except KeyboardInterrupt:
  74.         app.quitter()
  75.     except:
  76.         raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement