wxPython: Making your Frame Maximize or Full Screen

This topic comes up from time to time every year. Someone will ask about how to make their application full screen or how to just make it maximize when it first loads. So we’ll spend a little time showing you how to do each of these activities.

How to Maximize Your Frame

Occasionally you’ll want your wxPython application to be maximized when you first load it. Or perhaps you’ll want to have a sub-frame maximized. This is really easy to do in wxPython, but there is a little “gotcha” to watch out for. Let’s look at the code before we discuss the gotcha though:

Here we have a pretty standard set up using two classes, one a sub-class of wx.Panel and the other a sub-class of wx.Frame. To get it to Maximize, we just call the frame’s Maximize() method. Here’s where the gotcha comes in though. If you call Maximize before you call Show, you may see a glitch. For example, when I called Maximize first on Windows 7, the panel didn’t stretch to fully cover the frame correctly. See screenshot below:

As you can see, the frame is showing a little on the right hand side and along the bottom (the darker grey). So if you run the code above, the panel will cover the frame like it’s supposed to and it will look uniform. Occasionally you might need to also call your frame’s Raise() method to make it show up on top or at least cause the taskbar to blink a bit to get the user’s attention.

Making wxPython Show FullScreen

Personally, I haven’t found any good use cases for going full screen (i.e. covering up the entire screen) except for maybe a screen save type application or perhaps a photo viewer. But regardless, here’s the usual way of accomplishing this task:

Note that because the application is full screen, there is to title bar with a close button, so there’s no good way to close the application. Thus I added an event handler for key events such that the user can press ESC to close the application.

Wrapping Up

Now you should be familiar with how to make your own wxPython application go into a maximized state or even full screen. Good luck and happy coding!