Skip to content

Commit

Permalink
rename and build
Browse files Browse the repository at this point in the history
  • Loading branch information
federicodiluca committed Sep 21, 2024
1 parent 53742bf commit 20d82cc
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 4 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Fortune Wheel

Fortune Wheel is a Python application that simulates a spinning wheel of fortune. Users can spin the wheel and win random prizes defined in a JSON configuration file.

## Features

- Visualization of a fortune wheel with customizable prizes.
- Buttons to spin the wheel and stop it on a random prize.
- Simple prize configuration via a `fortuneWheel.json` file.

## Requirements

- Python 3.x
- The following Python libraries must be installed:
- `tkinter` (included in standard Python)
- `matplotlib`
- `numpy`

## Configuration

The `fortuneWheel.json` file contains the items for the wheel. You can modify it to add or remove prizes. Here’s an example of how the file should look:

```json
{
"title": "Ruota della fortuna",
"description": "Gira la ruota e scopri la prossima attività!",
"btnSpinText": "Gira la ruota",
"btnStopText": "Ferma la ruota",
"items": [
"Prize 1",
"Prize 2",
"Prize 3",
"Prize 4",
"Prize 5",
"Prize 6",
"Prize 7",
"Prize 8"
]
}
```

## Running the Application
To run the application, make sure to have the `fortuneWheel.json` file in the same directory as the executable. You can start the app with the following command:

```bash
python fortuneWheel.py
```

### Creating the Executable
You can generate an executable using `pyinstaller`. Make sure you have `pyinstaller` installed:

```bash
pip install pyinstaller
```

Then, run the command:

```bash
pyinstaller --clean fortuneWheel.spec
```
Binary file added assets/icon.ico
Binary file not shown.
File renamed without changes.
37 changes: 33 additions & 4 deletions program.py → fortuneWheel.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import tkinter as tk
import matplotlib.pyplot as plt
import numpy as np
import sys
import os
import json
import random
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

# Percorso relativo al file config.json
def get_config_path():
base_path = os.path.abspath(".")
return os.path.join(base_path, 'fortuneWheel.json')

# Leggere il file config.json
try:
with open(get_config_path(), 'r') as config_file:
config = json.load(config_file)
# print(config_file)
except FileNotFoundError:
print("File fortuneWheel.json non trovato.")
sys.exit(1)

config_path = get_config_path()

# Carica gli elementi dal file JSON
with open('config.json', 'r') as f:
with open(config_path, 'r') as f:
data = json.load(f)

title = data['title'].encode('latin1').decode('utf-8')
description = data['description'].encode('latin1').decode('utf-8')
btnSpinText = data['btnSpinText'].encode('latin1').decode('utf-8')
Expand Down Expand Up @@ -55,7 +74,7 @@ def stop_spinning():
global stop_requested
stop_requested = True
disable_stop_button() # Disabilita il pulsante "Stop" quando viene premuto

# Funzione che gestisce l'animazione della ruota
def spin_wheel():
global angle, spinning, speed, stop_requested
Expand All @@ -74,8 +93,10 @@ def spin_wheel():
if speed <= 0:
spinning = False
winner = items[int((angle % 360) / 360 * len(items))]
# Riabilita il pulsante "Inizia" quando la ruota si ferma
disable_spin_button()

# Riabilita il pulsante "Inizia" e disabilita il pulsante "Stop"
spin_button.config(state=tk.NORMAL)
stop_button.config(state=tk.DISABLED)
return

root.after(50, spin_wheel)
Expand All @@ -98,5 +119,13 @@ def spin_wheel():
stop_button = tk.Button(root, text=btnStopText, command=stop_spinning, font=("Arial", 12))
stop_button.pack(pady=10)

# Funzione per chiudere correttamente l'applicazione
def on_closing():
root.quit() # Ferma il main loop di tkinter
root.destroy() # Distrugge la finestra e chiude correttamente l'applicazione

# Configura la chiusura della finestra
root.protocol("WM_DELETE_WINDOW", on_closing)

# Avvio dell'app Tkinter
root.mainloop()
43 changes: 43 additions & 0 deletions fortuneWheel.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
['fortuneWheel.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='fortuneWheel',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=False, # Disabilita UPX
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['assets\\icon.ico'],
)


import shutil
shutil.copyfile('fortuneWheel.json', '{0}/fortuneWheel.json'.format(DISTPATH))

0 comments on commit 20d82cc

Please sign in to comment.