Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __Version__ = 1.0
- #Imports tkinter module for the GUI
- from tkinter import *
- #creates the initial GUI
- root = Tk()
- root.title('Converter')
- #root.iconbitmap(default='pennicon.ico')
- Label(text = 'Penn United Converter', bg='white', fg='blue').grid(row=1, column=1)
- Label(text = ' ').grid(row=2)
- #Creates the Label next to the entry box to let the user know what to enter
- Label(text = 'Units in MM', bg = "white", fg='blue' ).grid(row=3)
- #Function for clearing the entry fields
- def clear(entry):
- entry.delete(0, END)
- #Function to convert MM to inches
- def mm_to_inch(amt_in_mm):
- mm_per_inch = 25.4
- return amt_in_mm / mm_per_inch
- #Function to count the number of characters after the decimal place
- def digits_after_decimal_point(number):
- try:
- return (len(number.split('.')[1].strip()))
- except IndexError:
- return 0
- #Function for taking user input and converting it
- def convert_user_input(event):
- user_input = c.get()
- try:#Checks for a ValueError
- amt_in_mm = float(user_input)
- except ValueError:#If ValueError found clears the entry box and returns to main
- clear(c)
- return
- amt_in_inches = mm_to_inch(amt_in_mm)
- decimal_count = (digits_after_decimal_point(user_input))
- if decimal_count <= 2:#checks decimal count to see what place the number needs taken out to
- amt_in_inches = ("{0:.3f}".format(amt_in_inches))
- else:
- amt_in_inches = ("{0:.4f}".format(amt_in_inches))
- v.set(amt_in_inches)
- root.clipboard_clear()
- root.clipboard_append(amt_in_inches)
- clear(c)
- #Entry box for conversion
- c = Entry(root, width = 10)
- c.bind('<Return>', convert_user_input)
- c.grid(row=3, column=1)
- v = StringVar()
- Label(textvariable = v, width = 10).grid(row=4, column=1)
- #Label to let user know where to enter Surface input
- Label(text = 'RA Finish(MM)', bg = "white", fg='blue').grid(row=5)
- #Function for converting RA Finishes
- def surface(RA):
- try:#Trys for value error and defines variables
- float_roughness = float(RA)
- finish = (float_roughness / 25.4) * 1000
- results_finish = "{0:.0f}".format(finish)
- except ValueError:
- clear(s)
- return
- root.clipboard_clear()
- root.clipboard_append(results_finish)
- var.set(results_finish)
- clear(s)
- #Takes input for RA surface finsih conversion
- def surface_user_input(event):
- roughness = s.get()
- surface(roughness)
- #Entry box for RA Finish input
- s = Entry(root, width = 10)
- s.bind('<Return>', surface_user_input)
- var = StringVar()
- s.grid(row = 5, column = 1)
- Label(textvariable=var, width = 10).grid(row=6, column=1)
- #Label for Rz Finish input
- Label(text = 'Rz Finish', bg='white', fg='blue').grid(row=7, column=0)
- #Dictionary for Rz finish's
- Rz_dict = { '1' : '4', '2' : '8', '3' : '16', '4' : '16', '5' : '16',
- '6' : '32', '7' : '32', '8' : '32', '10' : '32', '16' : '64', '25' : '125',
- '32' : '125', '63' : '250'
- }
- #Function to get the correct Rz Value
- def Rz_Finish(event):
- Rz = str(r.get())
- Rz_RA = Rz_dict.get(Rz)
- Rz_var.set(Rz_RA)
- clear(r)
- #Rz finish input box
- r = Entry(root, width = 10)
- r.bind('<Return>',Rz_Finish)
- Rz_var = StringVar()
- r.grid(row=7, column=1)
- Label(textvariable=Rz_var, width = 20).grid(row=8, column=1)
- #Label for N type finish
- Label(text='N Type Finish', bg='white', fg='blue').grid(row=9, column=0)
- #N type dictionary
- N_type_dict = { '1' : '1', '2' : '2', '3' : '4', '4' : '8', '5' : '16','6' : '32',
- '7' : '63', '8' : '125', '9' : '250', '10' : '500', '11' : '1000', '12' : '2000'
- }
- def N_type_finish(event):
- N_type = str(n.get())
- N_converted = N_type_dict.get(N_type)
- N_var.set(N_converted)
- clear(n)
- #Entry box for N Type Finish
- n = Entry(root, width =10)
- n.bind('<Return>',N_type_finish)
- N_var = StringVar()
- n.grid(row=9, column=1)
- Label(textvariable=N_var, width=10).grid(row=10, column=1)
- #Function for the close button
- def quit():
- global root
- root.destroy()
- root.mainloop()
- Button(root, text='Close', command=quit).grid(row = 11, column = 4)
- main()
Advertisement
Add Comment
Please, Sign In to add comment