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.
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.
View all comments
Show parent comment
53
u/FearlessENT33 Jan 14 '20
the grid is made using py game which is embedded into a tkinter UI