Last active
October 26, 2017 05:49
-
-
Save wolfospealain/a7c442449c11a02afd024db7717905f6 to your computer and use it in GitHub Desktop.
Temperature Conversion GUI
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
""" | |
Conversion Functions | |
Eoin Ó Spealáin | |
October 2017 | |
""" | |
def c_to_f(temperature): | |
"""Converts temperature from Celsius to Fahrenheit.""" | |
f = temperature * 9/5 + 32 | |
return f | |
def f_to_c(temperature): | |
"""Converts temperature from Fahrenheit to Celsius.""" | |
c = (temperature - 32) * 5/9 | |
return c |
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
""" | |
Graphic User Interface for temperature conversion. | |
Eoin Ó Spealáin | |
2017 | |
""" | |
from tkinter import * | |
from conversions import * | |
def convert(): | |
fahrenheit.set(round(c_to_f(float(celsius.get())),1)) | |
return | |
# Create window | |
screen = Tk() | |
screen.title("Digital Thermometer") | |
screen.maxsize(width=200, height=130) | |
#screen.minsize(width=80, height=80) | |
screen.resizable(width=FALSE, height=FALSE) | |
# Setup variables | |
celsius = StringVar() | |
celsius.set(0.0) | |
fahrenheit = StringVar() | |
# Setup screen widgets | |
celsius_entry = Entry(width=10, textvariable=celsius, justify="right") # Text entry box | |
fahrenheit_entry = Entry(width=10, textvariable=fahrenheit, justify="right") | |
convert_button = Button(text="Convert", command=convert) | |
celsius_label = Label(text="Celsius") | |
fahrenheit_label = Label(text="Fahrenheit") | |
# Window placement commands | |
celsius_entry.place(x=20, y=20) # Add temperature box to window | |
#temperature.grid(row=1, column=2) # Grid method | |
#temperature.pack() # Pack method | |
celsius_label.place(x=110, y=20) | |
fahrenheit_entry.place(x=20, y=50) | |
fahrenheit_label.place(x=110, y=50) | |
convert_button.place(x=20, y=80) | |
# Keep program running | |
mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment