from Tkinter import *

def change_label(inputName, outputName, whichConversion):
	which = whichConversion.get();
	if (which==0):
		inputName.configure(text = "Fahrenheit");
		outputName.configure(text = "Celsius");
	elif (which==1):
		inputName.configure(text = "Celsius");
		outputName.configure(text = "Fahrenheit");
	
def convert(inVal, outputLabel, whichConversion):
	which = whichConversion.get();
	dval = 0.0;
	if (which==0):
		dval = fahrenheit_to_celsius(inVal.get());
	elif (which==1):
		dval = celsius_to_fahrenheit(inVal.get());
	
	outputLabel.configure(text = str(dval));

def fahrenheit_to_celsius(fahrenheit):
	celsius = (fahrenheit-32)*5.0/9.0;
	return celsius;

def celsius_to_fahrenheit(celsius):
	fahrenheit = celsius*9.0/5.0+32;
	return fahrenheit;

root = Tk()
inVal = DoubleVar();

outputLabel = Label(root, text="0.0", width=20);
outputLabel.grid(column=1,row=2);
outputName = Label(root, text="Celsius", width=20);
outputName.grid(column=1, row=1);

inputEntry = Entry(root, textvariable=inVal);
inputEntry.grid(column=0,row=2);
inputName = Label(root, text="Fahrenheit");
inputName.grid(column=0, row=1);

whichConversion = IntVar();
r1 = Radiobutton(root, text="fahrenheit to celsius", variable = whichConversion, value=0, 
					command=lambda : change_label(inputName, outputName, whichConversion));
r2 = Radiobutton(root, text="celsius to fahrenheit", variable = whichConversion, value=1, 
					command=lambda : change_label(inputName, outputName, whichConversion));
r1.grid(column=0, row=0);
r2.grid(column=1, row=0);


convertButton = Button(root, text="Convert", command= lambda : convert(inVal, outputLabel, whichConversion));
convertButton.grid(row=3, column=0, columnspan=2);

root.mainloop()