562 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owls only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Should you be using QT for Python as a GUI?
Part seven of an eight-part series of blogs
If you need to build a GUI system in Python, PyQt5 is probably the best choice, but don't take our word for it - read this blog and see what you think.
By far the easiest way to attach formatting to the widgets of a form is using a cascading style sheet. Here we have a simple form with absolutely no formatting:
The form looks drab, but CSS will sort this out.
For the title at the top of the form saying that CSS is great, we've added this dynamic property:
I probably should have mentioned that you can add your own properties to widgets earlier!
You could now create a style sheet - here's mine:
This style sheet sets a default Verdana 14 point font for all widgets, then sets specific formatting for QT labels, push buttons and any widgets to which we've attached the class h1_title.
You can then apply this in your code:
# opens style sheet and returns string of text containing CSS
with open(r"temp.css") as css_file:
css = css_file.read()
# apply CSS
This is what would appear when you run your form and click on the button:
In retrospect I should have put a bit more effort into making the styles look nice! Notice that the title appears in a different font size, because it has its dynamic property class set to h1_title.
This ability to attach CSS style sheets to GUI forms is a big selling-point to me for PyQt5.
|Parts of this blog|
25 Aytoun Street