from Tkinter import *

def change_label():
	global inputName;
	global outputName;
	global 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():
	global whichConversion;
	global outputLabel;
	global inVal;
	
	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();
frame = Frame(root);
frame.pack();

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

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

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

convertButton = Button(frame, text="Convert", command=convert);
convertButton.grid(row=3, column=0, columnspan=2);

root.mainloop()