PyQt Signals & Slots - PyQt

What is PyQt Signals & Slots?

Unlike a console mode application, which is completed in a sequential way, a GUI based application is event driven. functions or techniques are completed in reaction to user’s actions like clicking on a button, choosing an item from a set or a mouse click etc., known as events.

Widgets used to build the GUI interface act because the source of such activities. each PyQt widget, that is derived from QObject class, is designed to emit ‘signal’ in response to one or extra events. The signal on its own does not carry out any motion. instead, it is ‘related’ to a ‘slot’. The slot may be any callable Python function.

In PyQt, connection between a signal and a slot can be finished in specific methods. Following are most generally used techniques –

A more convenient way to call a slot_function, when a signal is emitted through a widget is as follows –

Suppose if a function is to be called when a button is clicked. here, the clicked sign is to be related to a callable feature. it can be completed in any of the following two techniques –



In the following example, QPushButton objects (b1 and b2) are introduced in QDialog window. We need to name functions b1_clicked() and b2_clicked() on clicking b1 and b2 respectively.

When b1 is clicked, the clicked() signal is attached to b1_clicked() feature.

When b2 is clicked, the clicked() signal is connected to b2_clicked() function


The above code produces the following output –

PyQt Signals & Slots


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

PyQt Topics