I have downloaded easygui and I've revised the code a bit:
# Filename: celsius.py
'''
this is for converting celsuis into fahrenheit. Hopefully to be
integrated into ctw'''
from easygui import *
import sys
msgbox("""
Welcome to Murray's Celsius Program,
based on Will's Celcius Program.""")
farenheit_degree = 5.0/9 # size of one Farenheit degree in Celsius
farenheit_offset = 32.0 # Zero Celsius = 32 Farenheit
absolute_zero = 0-273.15 # Celsius
def c2f(c):
"Celsius to Farenheit"
return c/farenheit_degree+farenheit_offset
def c2k(c):
"Celsius to Kelvin"
return c-absolute_zero
def f2c(f):
"Farenheit to Celsius"
return (f-farenheit_offset)*farenheit_degree
def f2r(f):
"Farenheit to Rankine"
c = f2c(f)
k = c2k(c)
return k/farenheit_degree
temp = 0.0
msg = 'Celsius temperature?'
title = 'Temperature Conversion'
while True:
reply = enterbox(msg, title, argDefaultText=temp)
if reply is None: break
temp = float(reply)
msg = """%.2f degrees Celsius
= %.2f degrees Farenheit;
= %.2f Kelvin;
= %.2f degrees Rankine.
"""% ( temp, c2f(temp), c2k(temp), f2r(c2f(temp)), )
This version handles the GUI a bit more elegantly by allowing the user to see the previous conversion and enter the new one at the same time. When the user clicks cancel the loop breaks and the program exits cleanly.