├── README.md ├── LICENSE └── task2.py /README.md: -------------------------------------------------------------------------------- 1 | # Technohacks_PP_02 2 | 3 | You can run the file in vscode and Pycharm. 4 | You have to install PyQt5 to run the file. 5 | Here's how you achieve this: 6 | 7 | > pip install PyQt5 8 | 9 | The output of the file looks like this: 10 | 11 | ![Capture](https://github.com/dawoodkhatri1/Technohacks_PP_02/assets/136968266/4c181f7a-5652-4866-92b7-debd9c7913e1) 12 | 13 | After Adding some value of Fahrenheit, the output looks like this: 14 | 15 | ![Capture2](https://github.com/dawoodkhatri1/Technohacks_PP_02/assets/136968266/196a702d-4001-48ac-af51-acb60ddc27c7) 16 | 17 | After Adding some value of Celsius, the output looks like this: 18 | 19 | ![Capture3](https://github.com/dawoodkhatri1/Technohacks_PP_02/assets/136968266/b0e48d65-98ce-42b7-9482-79895a450615) 20 | 21 | ## License 22 | 23 | [MIT License](LICENSE) 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Dawood M.Shoaib 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /task2.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton, QHBoxLayout 3 | 4 | 5 | class TempConverter(QWidget): 6 | def __init__(self): 7 | super().__init__() 8 | 9 | # Set up the window 10 | self.setWindowTitle('Temperature Converter') 11 | self.setStyleSheet("background-color: black;") 12 | 13 | # Layout 14 | layout = QVBoxLayout() 15 | 16 | # Input field for Fahrenheit 17 | self.fahrenheit_input = QLineEdit(self) 18 | self.fahrenheit_input.setStyleSheet("background-color: lightgray; color: black;") 19 | self.fahrenheit_input.setPlaceholderText('Enter temperature in Fahrenheit') 20 | layout.addWidget(self.fahrenheit_input) 21 | 22 | # Convert to Celsius button 23 | self.to_celsius_button = QPushButton('Convert to Celsius', self) 24 | self.to_celsius_button.setStyleSheet("background-color: blue; color: white;") 25 | self.to_celsius_button.clicked.connect(self.convert_to_celsius) 26 | layout.addWidget(self.to_celsius_button) 27 | 28 | # Input field for Celsius 29 | self.celsius_input = QLineEdit(self) 30 | self.celsius_input.setStyleSheet("background-color: lightgray; color: black;") 31 | self.celsius_input.setPlaceholderText('Enter temperature in Celsius') 32 | layout.addWidget(self.celsius_input) 33 | 34 | # Convert to Fahrenheit button 35 | self.to_fahrenheit_button = QPushButton('Convert to Fahrenheit', self) 36 | self.to_fahrenheit_button.setStyleSheet("background-color: blue; color: white;") 37 | self.to_fahrenheit_button.clicked.connect(self.convert_to_fahrenheit) 38 | layout.addWidget(self.to_fahrenheit_button) 39 | 40 | # Label to display the result 41 | self.result_label = QLabel('', self) 42 | self.result_label.setStyleSheet("background-color: yellow; color: black;") 43 | layout.addWidget(self.result_label) 44 | 45 | # Layout for the main window 46 | self.setLayout(layout) 47 | 48 | def convert_to_celsius(self): 49 | try: 50 | fahrenheit = float(self.fahrenheit_input.text()) 51 | celsius = (fahrenheit - 32) * 5.0 / 9.0 52 | self.result_label.setText(f'{fahrenheit}°F = {celsius:.2f}°C') 53 | except ValueError: 54 | self.result_label.setText('Invalid input for Fahrenheit') 55 | 56 | def convert_to_fahrenheit(self): 57 | try: 58 | celsius = float(self.celsius_input.text()) 59 | fahrenheit = celsius * 9.0 / 5.0 + 32 60 | self.result_label.setText(f'{celsius}°C = {fahrenheit:.2f}°F') 61 | except ValueError: 62 | self.result_label.setText('Invalid input for Celsius') 63 | 64 | 65 | if __name__ == '__main__': 66 | app = QApplication(sys.argv) 67 | converter = TempConverter() 68 | converter.show() 69 | sys.exit(app.exec_()) 70 | --------------------------------------------------------------------------------