2021-04-10 02:09:54

Hi all. I was wondering if anyone has any experience making a GUI using Pygame, and if so, any tips to offer? While digging around before posting, I found this SO thread, with a code example in the second answer that looks like it triggers items based on where the mouse is clicked on the screen, which I can't imagine would be accessible at is. Still, I'm assuming this would be easy enough to adapt with additional code that handles keyboard input. But I was wondering if there are any other solutions that allow for using on-screen widgets, such as those available through wxPython? I think I remember reading a while back that Pygame and wxPython don't play well together, so I'm assuming a combination like this isn't ideal?

Los Angeles Based musician, blogger, and programmer.
https://artistibarra.com/

2021-04-10 02:18:22

To my knowledge, and this may totally be incorrect, Pygame offers no native widget support, which means that all the GUI you're going to make has to be custom and thus inaccessible because it's just drawn on screen. Using WxPython and Pygame together is possible in theory, I say this only because you can probably show / hide windows and figure out how to make WX call the necessary functions within its event loop, but it's certainly not clean and not for the faint of heart. Short answer is just don't do it without a very good reason (I don't think mixing Pygame with GUI libraries to obtain an interface is a good enough reason). That being said, there's nothing preventing you from trying... aside from the frustrations you're going to experience while doing so.

2021-04-10 03:13:10

Ok, so technically you can make an accessible GUI with Pygame if you implement incredibly difficult to implement accessibility API stuff that's different for every platform and for which no one has a cross-platform solution, but this will take you months of effort at minimum--I mean actual months, not I do this  in the evening months--and no one else has already done it.  So for all practical purposes the answer is you can't.

If you are blind, and you don't care about graphics, you can do everything a game needs in WX no problem.  The event handling for keyboard and whatever is all there.  If you do care about graphics, you can do almost everything you need in wx, then get an OpenGL context out of it.  I don't know what the next step of that would be in Python; in C/C++ you can take that OpenGL context and give it to the OpenGL API, and in fact in those languages that's the normal way of getting one.  It's possible that Pyglet can do your rendering in that case because it's specifically written to interface with OpenGL and the other game-type stuff is sort of incidental, but you'd still need to actually have WX handling the GUI elements.  E.g. you'd put your graphics in a panel and use WX styling to overlay controls, or put the controls to the side, or something like that.

There's always plan C of giving all your controls keyboard support and then making them self-voicing, which does work, but for that your problem is that edit boxes are a difficult problem because you're reimplementing your own screen reader, so you'd have to e.g. use something like libfiledialogs or whatever it's called to pop normal ones up when the user wants to edit.  Also, I entirely hate how the world we live in is the "just hack it, this might be your best option because no one has cared enough to make this easy" one, but here we are.

My Blog
Twitter: @ajhicks1992

2021-04-10 04:33:43

As with many things it depends on what kind of GUI you have in mind, but the short answer is "yes". I've integrated Pyglet's OpenGL stack with wxPython before, and I know of a few scripts and examples that could help you do it. But you could also do it yourself with just Pygame or Pyglet, although you'd have to integrate a TTS engine like Tolk, UniversalSpeech, etc. and bind it manually to each UI element so your screen reader can respond, which is actually what I did with BrushTone. Mouse integration can be a bit more tricky, you can bind the mouse to the window and control it with the keyboard, but its a bit finicky with some libraries like wxPython.

I've also posted before [here] and a few other times about how to create GUI elements manually, basically you use Geometry. You create a fix resolution for your window, like 640 wide by 480 tall, then create your buttons which are x wide by y tall, and position them within the confines to the window. Design conventions and placement are just a matter of reference at that point.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2021-04-10 12:27:59

I once decided to add accessibility to a pygame-based game as well and had to re-implement tab navigation, input fields etc too.
You can get an idea of how it works within the corresponding repository of cards against humanity here.

2021-04-12 06:19:29

Thank you all so much for the detailed responses and resources. Though I still have a ton of refining to do, I'm finding that I really like the wx/Pyglet combination so far, and it seems like exactly the sort of thing I was hoping for.

Los Angeles Based musician, blogger, and programmer.
https://artistibarra.com/