Created
October 22, 2018 14:42
-
-
Save HarshaVardhanBabu/8e0131948316c48a8e183079861450ad to your computer and use it in GitHub Desktop.
Simple Converter app to understand tkinter framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Oct 22 19:26:07 2018 | |
@author: hnambur | |
""" | |
from tkinter import Label,Entry,Button,Tk | |
class Converter: | |
def __init__(self, master): | |
self.master = master | |
master.title("A simple GUI for type conversions") | |
def add_gui_elements(self): | |
# Adding the header | |
self.heading = Label(self.master,text="This app converts the temperature in Celcius to Kelvin") | |
self.heading.grid(column=0,row=0,columnspan=2) | |
# Adding the labels | |
self.label = Label(self.master, text="Enter temperature in Celcius") | |
self.label.grid(column=0,row=1) | |
# Add the input box for taking the user input | |
self.Tc_input = Entry(self.master) | |
self.Tc_input.grid(column=1,row=1) | |
# Add the label | |
self.label2 = Label(self.master, text="Temperature in Kelvin is :") | |
self.label2.grid(column=0,row=2) | |
# Add the label to display the new value | |
self.label3 = Label(self.master) | |
self.label3.grid(column=1,row=2) | |
# Button to convert the value | |
self.convert_button = Button(self.master, text="Convert", command=self.convert) | |
self.convert_button.grid(column=0,row=3,columnspan=2) | |
def convert(self): | |
# Utility function to convert the value | |
Tc = float(self.Tc_input.get()) | |
T_K = Tc + 273.15 | |
# Put the new value back in the label | |
self.label3.configure(text=str(T_K)) | |
if __name__ == "__main__": | |
root = Tk() # Create the main window | |
my_gui = Converter(root) # Create the converter Class | |
my_gui.add_gui_elements() # Add the UI elements to the window | |
root.mainloop() # Launch the UI thread |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment