diff --git a/Temperature_Converter/temperature_converter.py b/Temperature_Converter/temperature_converter.py index 105d19a..7aa945b 100644 --- a/Temperature_Converter/temperature_converter.py +++ b/Temperature_Converter/temperature_converter.py @@ -1,10 +1,9 @@ -# Temperature Converter -# Converts temperature between Celsius, Fahrenheit, and Kelvin - +from tkinter import * +window = Tk() +window.title("temperature_converter") def celsius_to_fahrenheit(celsius): return (celsius * 9 / 5) + 32 - def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32) * 5 / 9 @@ -24,39 +23,51 @@ def fahrenheit_to_kelvin(fahrenheit): def kelvin_to_fahrenheit(kelvin): return (kelvin - 273.15) * 9 / 5 + 32 - -def main(): - print("🌡️ Temperature Converter") - print("1. Celsius to Fahrenheit") - print("2. Fahrenheit to Celsius") - print("3. Celsius to Kelvin") - print("4. Kelvin to Celsius") - print("5. Fahrenheit to Kelvin") - print("6. Kelvin to Fahrenheit") - - choice = input("Enter choice (1–6): ") - - if choice == "1": - c = float(input("Enter Celsius: ")) - print(f"{c}°C = {celsius_to_fahrenheit(c):.2f}°F") - elif choice == "2": - f = float(input("Enter Fahrenheit: ")) - print(f"{f}°F = {fahrenheit_to_celsius(f):.2f}°C") - elif choice == "3": - c = float(input("Enter Celsius: ")) - print(f"{c}°C = {celsius_to_kelvin(c):.2f}K") - elif choice == "4": - k = float(input("Enter Kelvin: ")) - print(f"{k}K = {kelvin_to_celsius(k):.2f}°C") - elif choice == "5": - f = float(input("Enter Fahrenheit: ")) - print(f"{f}°F = {fahrenheit_to_kelvin(f):.2f}K") - elif choice == "6": - k = float(input("Enter Kelvin: ")) - print(f"{k}K = {kelvin_to_fahrenheit(k):.2f}°F") - else: - print("Invalid choice ❌") - - -if __name__ == "__main__": - main() +def ctf(): + inp = entry.get() + finp = float(inp) + entry.delete(0, END) + entry.insert(0,celsius_to_fahrenheit(finp)) +def ftc(): + inp = entry.get() + finp = float(inp) + entry.delete(0, END) + entry.insert(0,fahrenheit_to_celsius(finp)) +def ctk(): + inp = entry.get() + finp = float(inp) + entry.delete(0, END) + entry.insert(0,celsius_to_kelvin(finp)) +def ktc(): + inp = entry.get() + finp = float(inp) + entry.delete(0, END) + entry.insert(0,kelvin_to_celsius(finp)) +def ftk(): + inp = entry.get() + finp = float(inp) + entry.delete(0, END) + entry.insert(0,fahrenheit_to_kelvin(finp)) +def ktf(): + inp = entry.get() + finp = float(inp) + entry.delete(0, END) + entry.insert(0,kelvin_to_fahrenheit(finp)) + + +entry = Entry(window,bg="gray",fg="black",font="bold") +button1 = Button(window,bg="black",fg="white",font="bold",text="C t F",width=20,command=ctf) +button2 = Button(window,bg="black",fg="white",font="bold",text="F t C",width=20,command=ftc) +button3 = Button(window,bg="black",fg="white",font="bold",text="C t K",width=20,command=ctk) +button4 = Button(window,bg="black",fg="white",font="bold",text="K t C",width=20,command=ktc) +button5 = Button(window,bg="black",fg="white",font="bold",text="F t K",width=20,command=ftk) +button6 = Button(window,bg="black",fg="white",font="bold",text="K t F",width=20,command=ktf) +entry.pack(padx=50,pady=50) +button1.pack(side="left") +button2.pack(side="left") +button3.pack(side="left") +button4.pack(side="left") +button5.pack(side="left") +button6.pack(side="left") + +window.mainloop() \ No newline at end of file