diff --git a/.gitignore b/.gitignore index eb674d3e..2d8555bf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ /.vs /Tic_Tac_Toe/tic_tac_toe -OOP.py /.vscode +Converter/converter.py +Converter/converter_gui.py diff --git a/Converter/How to use unit converter GUI.gif b/Converter/How to use unit converter GUI.gif new file mode 100644 index 00000000..dc0eb75a Binary files /dev/null and b/Converter/How to use unit converter GUI.gif differ diff --git a/Converter/README.md b/Converter/README.md index 7181917e..056de66c 100644 --- a/Converter/README.md +++ b/Converter/README.md @@ -6,24 +6,58 @@
+
## 🛠️ Description
-A simple converter app built in python.
+A simple converter app built in Python. Now supports both command-line and graphical user interface (GUI) modes with PyQt5 or Tkinter.
## ⚙️ Languages or Frameworks Used
-You only need Python to run this script. You can visit here to download Python.
+- Python 3
+- PyQt5 (for modern GUI)
+- Tkinter (for classic GUI)
## 🌟 How to run
-Running the script is really simple! Just open a terminal in the folder where your script is located and run the following command:
+Open a terminal in the folder where your script is located and run one of the following commands:
+**For the classic command-line converter:**
```sh
python converter.py
```
+**For the GUI version (choose PyQt5 or Tkinter):**
+```sh
+python converter_gui.py
+```
+You will be prompted to select which GUI you prefer (`pyqt5` or `tkinter`).
+
+- If you choose `pyqt5`, make sure you have PyQt5 installed:
+ ```sh
+ pip install pyqt5
+ ```
+- If you choose `tkinter`, it is included with most Python installations by default.
+
## 📺 Demo
-
+
## 🤖 Author
[Alen Senson](https://github.com/AlenSenson)
+
+---
+
+### ✨ Features
+- Convert between units of Length, Area, Volume, Mass, and Time
+- Easy-to-use GUI (PyQt5 or Tkinter)
+- Command-line support
+- Help and symbols for all units
+
+### 📝 Usage (GUI)
+1. Select a unit category (e.g. Length, Area, Volume, Mass, Time)
+2. Select the starting unit (From unit)
+3. Enter the value you want to convert
+4. Select or type one or more target units (To unit(s)), separated by commas if more than one
+5. Click "Convert" to see the results
+6. For unit symbols, click "Symbols"
+
+---
diff --git a/Converter/__pycache__/converter_values.cpython-313.pyc b/Converter/__pycache__/converter_values.cpython-313.pyc
new file mode 100644
index 00000000..fbef9e82
Binary files /dev/null and b/Converter/__pycache__/converter_values.cpython-313.pyc differ
diff --git a/Converter/converter_gui.py b/Converter/converter_gui.py
new file mode 100644
index 00000000..3505ecd3
--- /dev/null
+++ b/Converter/converter_gui.py
@@ -0,0 +1,264 @@
+import sys
+print("Which GUI do you prefer? (pyqt5/tkinter)")
+gui_choice = input("Choice: ").strip().lower()
+
+if gui_choice == "pyqt5":
+ from PyQt5.QtWidgets import (
+ QApplication, QWidget, QLabel, QComboBox, QLineEdit, QPushButton, QTextEdit, QVBoxLayout, QHBoxLayout, QMessageBox
+ )
+ from converter_values import L, A, V, M, T, options
+
+ # Νέο help string για GUI
+ gui_help = '''\
+Unit Converter Instructions:
+
+1. Select a unit category (e.g. Length, Area, Volume, Mass, Time).
+2. Select the starting unit (From unit).
+3. Enter the value you want to convert.
+4. Select or type one or more target units (To unit(s)), separated by commas if more than one.
+5. Click "Convert" to see the results.
+
+To see the unit symbols, click "Symbols".
+'''
+
+ CATEGORY_MAP = {
+ 'Length': L,
+ 'Area': A,
+ 'Volume': V,
+ 'Mass': M,
+ 'Time': T
+ }
+
+ class ConverterGUI(QWidget):
+ def __init__(self):
+ super().__init__()
+ self.setWindowTitle('Unit Converter')
+ self.init_ui()
+
+ def init_ui(self):
+ layout = QVBoxLayout()
+
+ # Category selection
+ self.category_label = QLabel('Category:')
+ self.category_combo = QComboBox()
+ self.category_combo.addItems(CATEGORY_MAP.keys())
+ self.category_combo.currentTextChanged.connect(self.update_units)
+
+ # From unit
+ self.from_label = QLabel('From unit:')
+ self.from_combo = QComboBox()
+
+ # Value
+ self.value_label = QLabel('Value:')
+ self.value_edit = QLineEdit()
+ self.value_edit.setPlaceholderText('Enter value')
+
+ # To unit(s)
+ self.to_label = QLabel('To unit(s):')
+ self.to_combo = QComboBox()
+ self.to_combo.setEditable(True)
+ self.to_combo.setInsertPolicy(QComboBox.NoInsert)
+
+ # Convert button
+ self.convert_btn = QPushButton('Convert')
+ self.convert_btn.clicked.connect(self.convert)
+
+ # Result
+ self.result_text = QTextEdit()
+ self.result_text.setReadOnly(True)
+
+ # Help and Symbols
+ self.help_btn = QPushButton('Help')
+ self.help_btn.clicked.connect(self.show_help)
+ self.symbols_btn = QPushButton('Symbols')
+ self.symbols_btn.clicked.connect(self.show_symbols)
+
+ # Layouts
+ row1 = QHBoxLayout()
+ row1.addWidget(self.category_label)
+ row1.addWidget(self.category_combo)
+ row2 = QHBoxLayout()
+ row2.addWidget(self.from_label)
+ row2.addWidget(self.from_combo)
+ row3 = QHBoxLayout()
+ row3.addWidget(self.value_label)
+ row3.addWidget(self.value_edit)
+ row4 = QHBoxLayout()
+ row4.addWidget(self.to_label)
+ row4.addWidget(self.to_combo)
+ row5 = QHBoxLayout()
+ row5.addWidget(self.convert_btn)
+ row5.addWidget(self.help_btn)
+ row5.addWidget(self.symbols_btn)
+
+ layout.addLayout(row1)
+ layout.addLayout(row2)
+ layout.addLayout(row3)
+ layout.addLayout(row4)
+ layout.addLayout(row5)
+ layout.addWidget(self.result_text)
+
+ self.setLayout(layout)
+ self.update_units(self.category_combo.currentText())
+
+ def update_units(self, category):
+ units = list(CATEGORY_MAP[category].keys())
+ self.from_combo.clear()
+ self.from_combo.addItems(units)
+ self.to_combo.clear()
+ self.to_combo.addItems(units)
+
+ def convert(self):
+ category = self.category_combo.currentText()
+ from_unit = self.from_combo.currentText()
+ value_str = self.value_edit.text()
+ to_units = self.to_combo.currentText().split(',')
+ try:
+ value = float(value_str)
+ except ValueError:
+ QMessageBox.warning(self, 'Error', 'Invalid value!')
+ return
+ table = CATEGORY_MAP[category]
+ if from_unit not in table:
+ QMessageBox.warning(self, 'Error', 'Invalid from unit!')
+ return
+ results = []
+ for to_unit in to_units:
+ to_unit = to_unit.strip()
+ if to_unit not in table:
+ results.append(f"{to_unit}: Invalid unit")
+ continue
+ try:
+ result = round(value * table[to_unit] / table[from_unit], 6)
+ results.append(f"{to_unit}: {result}")
+ except Exception as e:
+ results.append(f"{to_unit}: Error")
+ self.result_text.setText('\n'.join(results))
+
+ def show_help(self):
+ QMessageBox.information(self, 'Help', gui_help)
+
+ def show_symbols(self):
+ QMessageBox.information(self, 'Symbols', options['symbols'])
+
+ if __name__ == '__main__':
+ app = QApplication(sys.argv)
+ window = ConverterGUI()
+ window.show()
+ sys.exit(app.exec_())
+
+elif gui_choice == "tkinter":
+ import tkinter as tk
+ from tkinter import ttk, messagebox
+ from converter_values import L, A, V, M, T, options
+
+ gui_help = '''\
+Unit Converter Instructions:
+
+1. Select a unit category (e.g. Length, Area, Volume, Mass, Time).
+2. Select the starting unit (From unit).
+3. Enter the value you want to convert.
+4. Select or type one or more target units (To unit(s)), separated by commas if more than one.
+5. Click "Convert" to see the results.
+
+To see the unit symbols, click "Symbols".
+'''
+
+ CATEGORY_MAP = {
+ 'Length': L,
+ 'Area': A,
+ 'Volume': V,
+ 'Mass': M,
+ 'Time': T
+ }
+
+ class ConverterTk(tk.Tk):
+ def __init__(self):
+ super().__init__()
+ self.title('Unit Converter')
+ self.geometry('400x400')
+ self.create_widgets()
+
+ def create_widgets(self):
+ # Category
+ tk.Label(self, text='Category:').pack()
+ self.category = ttk.Combobox(self, values=list(CATEGORY_MAP.keys()), state='readonly')
+ self.category.pack()
+ self.category.bind('<