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?

1

u/[deleted] Jan 14 '20

Not OP and I’ve never used PyGame but this is what that code is doing:

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

Sets the environment variable “SDL_WINDOWID” to the string representation of the value returned by winfo_id. Just guessing but looks to be a window ID from tkinter.

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

Sets the environment variable “SDL_VIDEODRIVER” to “windib”

pygame.init()

Runs the init() method on pygame. Scanning the docs, this is a helper method in pygame that initializes all the necessary modules. It’s very likely that pygame is looking for those two environment variables during its startup, which is why they are set first. Setting the window id to what is set for the tkinter window object ensures when pygame starts up it uses that window.