I want to create a GUI for a python program with a custom design, I have a mock-up in Photoshop and I'm looking for a library that supports theme or any other library that can do the job.
My GUI design contains gradients, borders, border radius, and a custom title bar with custom minimize and close buttons, for example take a look at the Github client for Windows, or any Adobe software installer.
I tried wxPython, I used style=wx.NO_BORDER
to remove the title bar and the default border added by Windows, but I feel like I'm not using the right tool for this job and I read somewhere that wxPython is mainly for native look GUI's and not meant for this kind of customization so I should look for something else.
I found an answer here recommending the use of PyQT and QML to make high customization in GUI's, but the compiled file have a very large size.
So what should I use to create a custom GUI ? I'm looking to compile the program too so I need to do it with a reasonable file size.
Your initial approach with wxPython is fine, you just need a couple more style flags for your top
wx.Frame
:Which will not only remove the border but the system menu and min/max/close boxes as well.
Then paint your gui background directly on the client area of your top frame. See this tutorial: and notice that
wx.DeviceContext
supports painting bitmaps and gradient fills.Now make your custom buttons and have them post
wx.CloseEvent
,wx.IconizeEvent
, andwx.MaximizeEvent
events when clicked. Lay them out on your custom frame using either absolute positioning or aSizer
. Done.Qt supports two main ways to customize the look (and feel):
Styles:For example Oxygen or the native Styles like the Windows style or the Mac style. Styles are rather complicated to develop as they need to directly interact with the underlying OS. You probably don't want this. Plus I don't think styles can be written in Python, but I may be wrong here.
Stylesheets: These are normal CSS stylesheets applied to your GUI. These are very flexible, can be changed at runtime, don't need any other code, can use resources like images and can influence or change most of the rendering.
This stylesheet for example just scratches the surface of the possible...
Please note that many users find custom GUI styles disruptive and/or bugging as they normally expect an application to look native, i.e. like all other applications. There are good reasons for custom GUIs, though, for example with imaging software one often wants GUIs with less contrast (like Adobe, Blender, etc. do it) in order to not disturb the image viewed/edited.
The huge advantage of using a widely used toolkit like Qt or GTK+ and customize it's looks is that usability is mostly preferred, whereas toolkits developed for games or similar usually expose inferior usability.
If you want something like the GitHub GUI, try PyGame. The window.NOFRAME property is available for removing the border.
I would recommend pyqt4 or pyside. It has the most robust gui development for python. It already comes with a handful of styles like:
And you can also create your own styles. This link is a good starting point:
Custom GUIs with wxPython/wxWidgets
You are correct that in general wxWidgets aims to provide a native look and feel by usually and by default using standard controls however the option exists not to do so. Install wxPython, in a recent version, then install the Docs & Demos package for the same version, and then run the demo and navigate to the Advanced Generic Widgets tab and you will find just about all of the features you are asking for demonstrated in the AUI demo. It does mention custom close, minimise, etc., the only thing you mention that is not in that one demo is gradient buttons. You will also find demos of gradient & aqua buttons, and a Zoom Bar - a la Mac but platform independent. screenshots of the AUI demo & the demo package on zoom bar are attached:
wxPython AGW AUI Screenshot:
Demo on Zoom Bar:
Note on file sizes:
I have been using wxPython for several years and my current main project provides a huge amount of functionality in 15-20 executables but py2exe gives me a set of distributable files that zip to under 35 Megabytes including documentation & re-distributable libraries - I had one very experienced person come up to me and demand to know where the rest of my deliverable package was hidden - was it on-line or was I pre-installing it in some other way - he was shocked to learn that it was all in the single zip file.