Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghackenberg/simpy-tkinter-boilerplate
Real-time visualization of discrete event simulation with SimPy and Tkinter
https://github.com/ghackenberg/simpy-tkinter-boilerplate
discrete-event-simulation multithreading python simpy tkinter
Last synced: about 1 month ago
JSON representation
Real-time visualization of discrete event simulation with SimPy and Tkinter
- Host: GitHub
- URL: https://github.com/ghackenberg/simpy-tkinter-boilerplate
- Owner: ghackenberg
- License: mit
- Created: 2022-08-19T14:42:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-12T22:06:40.000Z (9 months ago)
- Last Synced: 2024-04-14T11:32:16.782Z (9 months ago)
- Topics: discrete-event-simulation, multithreading, python, simpy, tkinter
- Language: Python
- Homepage:
- Size: 625 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SimPy + Tkinter Boilerplate
![](./images/social_preview.png)
This boilerplate project demonstrates the use of **Tkinter** for real-time visualization of discrete event simulations with **SimPy**.
## Examples
The following code snippet shows the basic structure of the simulation program. The simulation itself is executed in a separate simulation thread, while the GUI uses the main thread.
```python
import threading
import tkinter
import simpy
import simpy.rt# define the simulation ticks per second
ticks_per_second = 30
# define the total duration of the simulation run
duration = 10 * ticks_per_second# create Tkinter common objects here
window = tkinter.Tk()def run():
env = simpy.rt.RealtimeEnvironment(factor=1/ticks_per_second, strict=False)
# define SimPy events here
# create SimPy resources here
# attach SimPy processes here
env.run(until=duration)# run SimPy simulation event processing in simulation thread
thread = threading.Thread(target=run)
thread.start()# run Tkinter interaction event processing and component rendering in main thread
window.mainloop()
```## Screenshots
When executing the simulation program, you should see the following real-time visualization.
![Screenshot](./images/screenshot.png)
## Guides
### Prepare the development environment
Download and install the SimPy discrete event simulation library.
```
pip install simpy
```### Run the simulation program
Execute the simulation program with your standard Python interpreter.
```
python ./sources/main.py
```