From e238ae304cb08910c21a9c4dd84c292bf4cbc07d Mon Sep 17 00:00:00 2001 From: blackguy Date: Sat, 14 Nov 2026 00:52:48 +0500 Subject: [PATCH 1/2] added GUI in temprature_converter --- .../temperature_converter.py | 115 ++++++++++++------ 1 file changed, 78 insertions(+), 37 deletions(-) diff --git a/Temperature_Converter/temperature_converter.py b/Temperature_Converter/temperature_converter.py index 105d19a..6127cb7 100644 --- a/Temperature_Converter/temperature_converter.py +++ b/Temperature_Converter/temperature_converter.py @@ -1,9 +1,85 @@ -# Temperature Converter -# Converts temperature between Celsius, Fahrenheit, and Kelvin +from tkinter import * def celsius_to_fahrenheit(celsius): return (celsius * 9 / 5) + 32 +def fahrenheit_to_celsius(fahrenheit): + return (fahrenheit - 32) * 5 / 9 + + +def celsius_to_kelvin(celsius): + return celsius + 273.15 + + +def kelvin_to_celsius(kelvin): + return kelvin - 273.15 + + +def fahrenheit_to_kelvin(fahrenheit): + return (fahrenheit - 32) * 5 / 9 + 273.15 + + +def kelvin_to_fahrenheit(kelvin): + return (kelvin - 273.15) * 9 / 5 + 32 + +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)) + + + + + + +window = Tk() + +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() + + def fahrenheit_to_celsius(fahrenheit): return (fahrenheit - 32) * 5 / 9 @@ -25,38 +101,3 @@ 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() From 5f4daf584b6e7bd21c4c11c521ebf24ef7ca75f7 Mon Sep 17 00:00:00 2001 From: blackguy Date: Sat, 14 Nov 2026 00:58:11 +0500 Subject: [PATCH 2/2] added titel --- .../temperature_converter.py | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/Temperature_Converter/temperature_converter.py b/Temperature_Converter/temperature_converter.py index 6127cb7..7aa945b 100644 --- a/Temperature_Converter/temperature_converter.py +++ b/Temperature_Converter/temperature_converter.py @@ -1,5 +1,6 @@ from tkinter import * - +window = Tk() +window.title("temperature_converter") def celsius_to_fahrenheit(celsius): return (celsius * 9 / 5) + 32 @@ -54,12 +55,6 @@ def ktf(): entry.insert(0,kelvin_to_fahrenheit(finp)) - - - - -window = Tk() - 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) @@ -75,29 +70,4 @@ def ktf(): button5.pack(side="left") button6.pack(side="left") - - -window.mainloop() - - - -def fahrenheit_to_celsius(fahrenheit): - return (fahrenheit - 32) * 5 / 9 - - -def celsius_to_kelvin(celsius): - return celsius + 273.15 - - -def kelvin_to_celsius(kelvin): - return kelvin - 273.15 - - -def fahrenheit_to_kelvin(fahrenheit): - return (fahrenheit - 32) * 5 / 9 + 273.15 - - -def kelvin_to_fahrenheit(kelvin): - return (kelvin - 273.15) * 9 / 5 + 32 - - +window.mainloop() \ No newline at end of file