ECS with Python and Tkinter, Part 1
[Dynamic Link — Static Link]
Posted: 2020-12-09
Last Edited: 2020-12-09
The Specification
Recently at Uni we was given a piece of coursework to write a game in python, except that we weren't allowed to use any non-standard features (no pip). This meant that we were not allowed to use pygame, pillow, or any other useful library that sane people (especially busy professionals with many important things to do) would like to use. Now, im no professional and i certainly don't have many important things to do, but even i see the sense in reusing existing code. Its faster, less error prone, and helps you keep sane. However, this was not allowed by the cousework specification, leaving only tkinter as the GUI library of (forced) choice.
Tkinter as a Game Engine
For fun and profit i decided to write an ECS game engine in python. Partly because i haven't ever done an ECS engine and wanted to learn about the upsides and downsides of the ECS paradigm. Partly because i hate myself. Mainly because python is inherently slow and i wanted to make the game engine as fast as possible to amortize the cost of the language. Thus i started reading up about ECS and Tkinter. A great resource for Tk is effbot.org, which i used extensively during the course of researching for the engine. It seems to be down as of 08-12-2020, which is a shame, but it is still accessible on the wayback machine.
Whilst i may be come off as negative towards Tkinter, after working with it for a bit i think its quite good. Its performance surprised me, as it was easily able to draw thousands of canvas entities and move them around without issue at 60 frames per second. It was also really easy to work with, with a simple Tk() call to initialise the entire library and then a single Canvas() and canvas.pack() call to make the game screen show up.
Overall i enjoyed the project, and ill be writing up some further explanations of the ECS engine itself. For now, the code for the game engine is available on my GitHub here.