diff --git a/Temperature-Converter/README.md b/Temperature-Converter/README.md new file mode 100644 index 00000000..aa356b2d --- /dev/null +++ b/Temperature-Converter/README.md @@ -0,0 +1,32 @@ +Temperature Converter + + +A simple temperature converter application built with Python and tkinter. This application allows you to convert temperature values between Celsius, Fahrenheit, and Kelvin. + +Features + + +Convert temperature values between Celsius, Fahrenheit, and Kelvin. +User-friendly graphical user interface (GUI) built with tkinter. + +Getting Started + + +Clone the repository or download the script file temperature_converter.py to your local machine. + +Install the required dependencies by running the following command: +pip install tkinter + +Run the script using the following command: +python temperature_converter.py + +Enter the temperature value in the input field. + +Select the input unit from the dropdown menu. + +Choose the desired output unit using the radio buttons. + +Click the "Convert" button to perform the temperature conversion. + +The converted temperature will be displayed in a pop-up dialog box. + diff --git a/Temperature-Converter/temp-converter.py b/Temperature-Converter/temp-converter.py new file mode 100644 index 00000000..d9c5e2b8 --- /dev/null +++ b/Temperature-Converter/temp-converter.py @@ -0,0 +1,69 @@ +import tkinter as tk +from tkinter import messagebox + +def convert_temperature(): + temperature = entry.get() + try: + temperature = float(temperature) + selected_unit = unit_choices.get() + + if selected_unit == "Celsius": + if selected_choice.get() == "Kelvin": + converted_temp = temperature + 273.15 + messagebox.showinfo("Conversion Result", f"{temperature}°C is equivalent to {converted_temp} K") + elif selected_choice.get() == "Fahrenheit": + converted_temp = (temperature * 9/5) + 32 + messagebox.showinfo("Conversion Result", f"{temperature}°C is equivalent to {converted_temp}°F") + + elif selected_unit == "Kelvin": + if selected_choice.get() == "Celsius": + converted_temp = temperature - 273.15 + messagebox.showinfo("Conversion Result", f"{temperature} K is equivalent to {converted_temp}°C") + elif selected_choice.get() == "Fahrenheit": + converted_temp = (temperature - 273.15) * 9/5 + 32 + messagebox.showinfo("Conversion Result", f"{temperature} K is equivalent to {converted_temp}°F") + + elif selected_unit == "Fahrenheit": + if selected_choice.get() == "Celsius": + converted_temp = (temperature - 32) * 5/9 + messagebox.showinfo("Conversion Result", f"{temperature}°F is equivalent to {converted_temp}°C") + elif selected_choice.get() == "Kelvin": + converted_temp = (temperature - 32) * 5/9 + 273.15 + messagebox.showinfo("Conversion Result", f"{temperature}°F is equivalent to {converted_temp} K") + + except ValueError: + messagebox.showerror("Error", "Please enter a valid temperature value.") + +# Create the tkinter window +window = tk.Tk() +window.title("Temperature Converter") +window.geometry("300x200") # Set the initial window size + +# Create the entry field +entry = tk.Entry(window) +entry.pack() + +# Create the dropdown menu for temperature unit choices +unit_choices = tk.StringVar(window) +unit_choices.set("Celsius") # Set the default unit as Celsius +unit_dropdown = tk.OptionMenu(window, unit_choices, "Celsius", "Kelvin", "Fahrenheit") +unit_dropdown.pack() + +# Create the radio buttons for temperature choices +selected_choice = tk.StringVar(window, "Celsius") # Set the default choice as Celsius + +kelvin_radio = tk.Radiobutton(window, text="Kelvin", variable=selected_choice, value="Kelvin") +kelvin_radio.pack() + +celsius_radio = tk.Radiobutton(window, text="Celsius", variable=selected_choice, value="Celsius") +celsius_radio.pack() + +fahrenheit_radio = tk.Radiobutton(window, text="Fahrenheit", variable=selected_choice, value="Fahrenheit") +fahrenheit_radio.pack() + +# Create the conversion button +convert_button = tk.Button(window, text="Convert", command=convert_temperature) +convert_button.pack() + +# Run the tkinter event loop +window.mainloop()