Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
547 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers 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
Search our website
We also send out useful tips in a monthly email newsletter ...
Should you be using QT for Python as a GUI? Part six 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.
|
To get buttons (or other widgets) to do something when you click on them or change them, you listen for the signals that they emit and assign these to slots.
To show how this works, suppose that you have a simple form containing a single label and single push button:
We've called the label lblOwlMessage and the button btnShowOwlMessage.
We hide the label when the form loads (you could do this in QT Designer instead):
# hide the message to start
self.lblOwlMessage: QLabel = self.findChild(QLabel,'lblOwlMessage')
self.lblOwlMessage.setVisible(False)
Next we create a slot to handle the event of clicking on the button (in most Microsoft applications this would be called an event-handler):
def show_message(self):
# show the hidden label
self.lblOwlMessage.setVisible(True)
Finally, we connect the clicked signal from the push button to the show_message slot above:
# get push button to do something
self.btnShowOwlMessage: QPushButton = self.findChild(QPushButton,'btnShowOwlMessage')
self.btnShowOwlMessage.clicked.connect(self.show_message)
The range of signals emitted by widgets is mind-boggling, but having to tie them to slots is a bit tedious.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.