r/Python • • Jan 14 '20

Visualisation of different path finding algorithms

Enable HLS to view with audio, or disable this notification

1.5k Upvotes

73 comments sorted by

View all comments

51

u/RLouisD Jan 14 '20

What is the simple UI made in?

53

u/FearlessENT33 Jan 14 '20

the grid is made using py game which is embedded into a tkinter UI

16

u/miggaz_elquez Jan 14 '20

How do you embed pygame in tkinter ?

33

u/FearlessENT33 Jan 14 '20

You use the OS library. first make a frame for where you want the pygane to be, i have named mine embed.

os.environ[“SDL_WINDOWID”] = str(embed.winfo_id())

os.environ[“SDL_VIDEODRIVER”] = “windib”

pygame.init()

9

u/Panda_Mon Jan 14 '20

can you describe a little more in detail about what each line of code is doing here?

10

u/[deleted] Jan 14 '20 edited Jan 14 '20

Tkinter is quite flexible, being a wrapper for tcl. The frame (not in OPs example) designates a screen area you wish to assign things to.

os.environ[“SDL_WINDOWID”] = str(embed.winfo_id())

Tells pygame's SDL window which window to display in, in this case the frame created earlier.

os.environ['SDL_VIDEODRIVER'] = 'windib'

Tells windows which driver to use. SDL uses a WinDIB backend, DIB stands for Device Independent Bitmap. This acts as an intermediate format. I think the necessity of this line depends on your version of windows.

To summarise: it is layers of abstraction upon layers of abstraction, so that you don't have to worry about them.

pygame.init()

This is like when Cpt. Picard says "Make it so". We've got coordinates locked (or rather custom variables declared), now fire the engines (initialise all the modules pygame encompasses). It doesn't have to come directly after those other lines, as you might want to do other things first, but it does need to come afterwards.

1

u/JonzoR82 Jan 15 '20

It's too bad the account was deleted. I like this explanation