Question:
Python Programming (easygui.py)?
wesley_morris2000
2008-01-08 17:09:37 UTC
I wrote a program to convert Celsius into Fahrenheit. I know nothing about gui building with python. I want to take the users input of the Celsius temp and have it converted it to Fahrenheit in the gui using easygui.py. Here is the code:

#!/usr/bin/python
# Filename: celcius.py
'''
this is for converting celsuis into fahrenheit. Hopefully to be
integrated into ctw'''

from easygui import *
import sys

msgbox("Welcome to Will's Celcius Program.")




temp = input('What\'s the Celsuis Temperature? ')

print 'The Fahrenheit Temperature is', temp * 1.8 + 32

msg ="Would you like to convert again?"
title = "Loop Box"
if boolbox(msg, title): #show a contimue/cancel dialog
False
else:
sys.exit(0) #user chose cancel
Three answers:
poorcocoboiboi
2008-01-08 19:12:23 UTC
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.
?
2016-11-08 12:02:17 UTC
Python Easygui
?
2016-12-01 10:34:37 UTC
in case you are able to desire to make video games C++ is the main prevalent language, yet C#, Java, and Python are much less demanding to comprehend. in case you attempt to start with C++ you have gotten an exceedingly puzzling time.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...