Skip to content

Implemented GUI password generator, removed file due to Windows restrictions, and improved script converter functionality #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/.vs
/Tic_Tac_Toe/tic_tac_toe -OOP.py
/.vscode
Converter/converter.py
Converter/converter_gui.py
Binary file added Converter/How to use unit converter GUI.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 38 additions & 4 deletions Converter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,58 @@

<p align="center">
<img src="https://github.com/AlenSenson/python-mini-project/blob/main/Converter/images.png" width=20% height=20%>
<img src="" width=20% height=20%>


## 🛠️ 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
<p align="center">
<img src="https://github.com/AlenSenson/python-mini-project/blob/main/Converter/Screenshot%202023-05-31%20180831.png" width=70% height=70%>
<img src="https://github.com/programmer632/python-mini-project/blob/main/Converter/How%20to%20use%20unit%20converter%20GUI.gif" width=70% height=70%>

## 🤖 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"

---
Binary file not shown.
264 changes: 264 additions & 0 deletions Converter/converter_gui.py
Original file line number Diff line number Diff line change
@@ -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('<<ComboboxSelected>>', self.update_units)
self.category.current(0)

# From unit
tk.Label(self, text='From unit:').pack()
self.from_unit = ttk.Combobox(self, state='readonly')
self.from_unit.pack()

# Value
tk.Label(self, text='Value:').pack()
self.value_entry = tk.Entry(self)
self.value_entry.pack()

# To unit(s) - editable ComboBox
tk.Label(self, text='To unit(s) (comma separated):').pack()
self.to_units = ttk.Combobox(self)
self.to_units.pack()

# Convert button
tk.Button(self, text='Convert', command=self.convert).pack(pady=5)
# Help and Symbols
tk.Button(self, text='Help', command=self.show_help).pack(side='left', padx=10, pady=5)
tk.Button(self, text='Symbols', command=self.show_symbols).pack(side='right', padx=10, pady=5)

# Result
self.result = tk.Text(self, height=10, width=40)
self.result.pack(pady=10)

self.update_units()

def update_units(self, event=None):
cat = self.category.get() if hasattr(self, 'category') else list(CATEGORY_MAP.keys())[0]
units = list(CATEGORY_MAP[cat].keys())
self.from_unit['values'] = units
self.from_unit.current(0)
self.to_units['values'] = units
if units:
self.to_units.set(units[0])

def convert(self):
cat = self.category.get()
from_unit = self.from_unit.get()
value_str = self.value_entry.get()
to_units = self.to_units.get().split(',')
try:
value = float(value_str)
except ValueError:
messagebox.showwarning('Error', 'Invalid value!')
return
table = CATEGORY_MAP[cat]
if from_unit not in table:
messagebox.showwarning('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:
results.append(f"{to_unit}: Error")
self.result.delete('1.0', tk.END)
self.result.insert(tk.END, '\n'.join(results))

def show_help(self):
messagebox.showinfo('Help', gui_help)

def show_symbols(self):
messagebox.showinfo('Symbols', options['symbols'])

if __name__ == '__main__':
app = ConverterTk()
app.mainloop()
else:
print("Invalid choice. Please run the program again and select 'pyqt5' or 'tkinter'.")
Binary file not shown.
Loading