Guest User

Untitled

a guest
Oct 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Oct 22 19:26:07 2018
  4.  
  5. @author: hnambur
  6. """
  7.  
  8. from tkinter import Label,Entry,Button,Tk
  9.  
  10. class Converter:
  11. def __init__(self, master):
  12. self.master = master
  13. master.title("A simple GUI for type conversions")
  14.  
  15. def add_gui_elements(self):
  16.  
  17. # Adding the header
  18. self.heading = Label(self.master,text="This app converts the temperature in Celcius to Kelvin")
  19. self.heading.grid(column=0,row=0,columnspan=2)
  20. # Adding the labels
  21. self.label = Label(self.master, text="Enter temperature in Celcius")
  22. self.label.grid(column=0,row=1)
  23. # Add the input box for taking the user input
  24. self.Tc_input = Entry(self.master)
  25. self.Tc_input.grid(column=1,row=1)
  26. # Add the label
  27. self.label2 = Label(self.master, text="Temperature in Kelvin is :")
  28. self.label2.grid(column=0,row=2)
  29. # Add the label to display the new value
  30. self.label3 = Label(self.master)
  31. self.label3.grid(column=1,row=2)
  32. # Button to convert the value
  33. self.convert_button = Button(self.master, text="Convert", command=self.convert)
  34. self.convert_button.grid(column=0,row=3,columnspan=2)
  35.  
  36. def convert(self):
  37. # Utility function to convert the value
  38. Tc = float(self.Tc_input.get())
  39. T_K = Tc + 273.15
  40. # Put the new value back in the label
  41. self.label3.configure(text=str(T_K))
  42.  
  43. if __name__ == "__main__":
  44. root = Tk() # Create the main window
  45. my_gui = Converter(root) # Create the converter Class
  46. my_gui.add_gui_elements() # Add the UI elements to the window
  47. root.mainloop() # Launch the UI thread
Add Comment
Please, Sign In to add comment