Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from math import pi
- class RMP_mesure:
- def __init__(self):
- self.quit = False
- self.root = Tk()
- self.root.protocol("WM_DELETE_WINDOW", self.quitter)
- self.root.title("RPM Converter")
- self.root.geometry("250x100+100+100")
- self.root.configure(bg="white")
- self.output = None
- def calc(self, event, rd, rp):
- try:
- rd = float(rd.get())
- except:
- self.output.delete(0, END)
- self.output.insert(0, "Please insert Radius as a floating point number")
- self.output.configure(fg="red")
- try:
- rp = int(rp.get())
- except:
- self.output.delete(0, END)
- self.output.insert(0, "Please insert RPM as a floating point number")
- self.output.configure(fg="red")
- rps = rp/60
- c = 2*pi*rd
- dis = c*rps
- mps = dis/100
- self.output.delete(0, END)
- self.output.insert(0, "%s m/s"%str(mps)[0:str(mps).index(".")+3])
- self.output.configure(fg="black")
- def run(self):
- f1 = Frame(self.root, bg="white")
- f1.pack(side=TOP, fill=X)
- f2 = Frame(self.root, bg="white")
- f2.pack(side=TOP, fill=X)
- f3 = Frame(self.root, bg="white")
- f3.pack(side=TOP, fill=X)
- f4 = Frame(self.root, bg="white")
- f4.pack(side=TOP, fill=X)
- Label(f1, text="Radius(cm)", width=10, justify=RIGHT, anchor="e", bg="white").pack(side=LEFT)
- rd = Entry(f1)
- rd.pack(side=LEFT, fill=X)
- Label(f2, text="RPM", width=10, justify=RIGHT, anchor="e", bg="white").pack(side=LEFT)
- rp = Entry(f2)
- rp.pack(side=LEFT, fill=X)
- self.output = Entry(f3, bg="white", fg="black")
- self.output.pack(fill=X, expand=1)
- Button(f4, text="Calculate", bg="white", command=lambda e=Event(), rd=rd, rp=rp: self.calc(e, rd, rp)).pack(fill=X, expand=1)
- while not self.quit:
- self.root.update()
- self.root.update_idletasks()
- def quitter(self):
- self.quit = True
- if __name__ == "__main__":
- app = RMP_mesure()
- try:
- app.run()
- except KeyboardInterrupt:
- app.quitter()
- except:
- raise
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement