PyQt6 Tutorials
About Lesson

In this PyQt6 lesson we are going to learn about PyQt6 QPushButton and QLabel, so using QPushButton class we can create buttons in PyQt6 and using QLabel class we can create labels. 

 

 

What is PyQt6 QLabel ?

PyQt6 QLabel is user interface (UI) widget in PyQt6 library that is used to display text or images in graphical user interface (GUI). QLabel is subclass of the QWidget class and provides simple way to display text and images in a window or dialog.

With QLabel widget, you can display static text or dynamic text that changes in response to user input or other events. you can also use the QLabel to display images, such as icons or logos, by setting the pixmap property of the QLabel to the desired image.

in addition to displaying text and images, QLabel widget provides several properties and methods that allow you to customize the appearance and behavior of the widget. for example you can set the font and color of the text displayed by the QLabel, and you can use the setText() method to change the text displayed by the widget at runtime.

some common use cases for QLabel include displaying static text or images in a welcome screen or about dialog, displaying dynamic text or images that change based on user input or other events, and displaying help or error messages to the user.

to use the QLabel widget in PyQt6 application, you would first create an instance of the QLabel class and set its text or image properties using setText() or setPixmap() method. you can also customize the appearance and behavior of the QLabel by setting its properties, such as its font or alignment, or by connecting its signals to slots that handle user input or other events.

 

 

What is PyQt6 QPushButton ?

PyQt6 QPushButton is user interface (UI) widget in PyQt6 library that provides push button that the user can click to perform an action or trigger an event in a graphical user interface (GUI). QPushButton is subclass of the QAbstractButton class and provides simple way to add interactive buttons to your PyQt6 applications.

with QPushButton widget, you can add button to your application that the user can click to perform an action, such as saving file, submitting form, or initiating search. you can customize the appearance of the QPushButton by setting its properties, such as its text, font, icon, and tooltip.

in addition to providing a simple way to add interactive buttons to your application, the QPushButton widget also provides several signals and slots that allow you to handle user input and other events. For example, you can connect the clicked() signal of the QPushButton to a slot that performs the desired action when the button is clicked.

Some common use cases for QPushButton include adding buttons to a toolbar or menu bar, adding buttons to a form or dialog box, or adding buttons to a main window or status bar.

To use the QPushButton widget in a PyQt6 application, you would first create an instance of the QPushButton class and set its properties, such as its text or icon, using the setText() or setIcon() method. You can also connect its signals to slots that handle user input or other events using the connect() method.

 

 

 

This is the complete code for this lesson.

 

 

 

We have created the object of QPushButton class, you need to give the text for the button and also the parent of self.

 

 

Using this code you can move your button in the X and Y direction.

 

 

If you want to set the X and Y position, also the width and height of the button than you can use this code.

 

 

In here we have given a background color with icon to the button.

 

 

This is our label, we have used QLabel class for creating label in PyQt6.

 

 

 

Run the complete code and this is the result.

PyQt6 QPushButton & QLabel
PyQt6 QPushButton and QLabel