Guest User

Untitled

a guest
May 9th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. import tkinter #<imports kinter module
  2. from tkinter import * #<and * from the tkinter module
  3. from tkinter import Tk #<and Tk from the tkinter module
  4. import sys#imports sys (allows to use functions such as timesleep
  5.  
  6. convert_formula = 25.4#the number needed to divide by to convert MM to Inches as a variable
  7. root = Tk()#sets root = Tk()
  8. root.title('Converter')#creates a title in the Tk Widget
  9. Label(text = 'Welcome to the converter').pack(side = TOP, padx = 10, pady = 10)#Just a little intro in the Tk widget
  10.  
  11. def convert(Num_In_MM):#This is the conversion function, sets the rules and restrictions when converting a unit of measure from MM to Inches
  12. Num_In_MM = float(e.get())#Gets user input from the entry widget created by tkinter (see below)
  13. Results = ("%.3f" % (Num_In_MM / convert_formula))#creates a variable from the users input divided by convert_fomula(25.4) and saves the results to the 3rd decimal places (thousanths)
  14. print(Results)#Prints the float stored in the variable Results
  15.  
  16. def quit():#Creates a quit function for the quit button on the Tk Widget
  17. global root
  18. root.destroy()#destroys the widget(closes it)
  19.  
  20. e = Entry(root, width = 5)#Creates an entry box to get user input
  21. e.bind('<Return>', convert)#binds the entry box to <Return> (Enter key) so the user can hit enter to get the results
  22. e.pack(side = TOP, padx = 10, pady = 10)#this just packs the widget
  23.  
  24. Button(root, text='quit', command=quit).pack(side= RIGHT)#creates a quit button on the widget
  25.  
  26. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment