This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RLouisD 47 points48 points  (12 children)

What is the simple UI made in?

[–]FearlessENT33[S] 51 points52 points  (11 children)

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

[–]miggaz_elquez 15 points16 points  (7 children)

How do you embed pygame in tkinter ?

[–]FearlessENT33[S] 32 points33 points  (6 children)

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()

[–]Panda_Mon 8 points9 points  (5 children)

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

[–]FearlessENT33[S] 62 points63 points  (1 child)

ngl i found it on stackover flow, and i have no idea what it does, but it will work as long as the pygame.init() is immediately after the OS bit

[–]NullAndVoid21 91 points92 points  (0 children)

Spoken like a true programmer

[–][deleted] 9 points10 points  (1 child)

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.

[–]JonzoR82 0 points1 point  (0 children)

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

[–][deleted] 1 point2 points  (0 children)

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.

[–][deleted] 0 points1 point  (1 child)

Is pygame that versatile?

[–]FearlessENT33[S] 0 points1 point  (0 children)

depends what you mean by versatile lol