In this PyQt5 GUI article i want to show you Creating QScrollArea. The QScrollArea class provides a scrolling view onto another widget.A scroll area is used to display the contents of a child widget within a frame. If the widget exceeds the size of the frame, the view can provide scroll bars so that the entire area of the child widget can be viewed.
Also you can check more Python articles in the below links
1: Complete PyQt5 GUI Development Course
2: Python TKinter GUI Development
First we need some imports
|
1 2 3 |
from PyQt5 import QtGui from PyQt5.QtWidgets import QApplication, QWidget, QScrollArea, QVBoxLayout, QGroupBox, QLabel, QPushButton, QFormLayout import sys |
After that we are going to create our main Window class that extends from QWidget. and in the constructor of the class we need to add some requirements of the window like set window title, window icon and window geometry.
and in the constructor we have added a val, because we want to add some value in there.
|
1 2 3 4 5 6 7 8 9 10 11 |
class Window(QWidget): def __init__(self, val): super().__init__() self.title = "PyQt5 Scroll Bar" self.top = 200 self.left = 500 self.width = 400 self.height = 300 self.setWindowIcon(QtGui.QIcon("icon.png")) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) |
In here we going to create the object of QFormLayout and QGroupBox. also we have created two empty lists.
|
1 2 3 4 |
formLayout =QFormLayout() groupBox = QGroupBox("This Is Group Box") labelLis = [] comboList = [] |
Using this code we want to create some buttons to add in the window for testing the scroll of the window.
|
1 2 3 4 |
for i in range(val): labelLis.append(QLabel("Label")) comboList.append(QPushButton("Click Me")) formLayout.addRow(labelLis[i], comboList[i]) |
Also every PyQt5 application must create an application object. The sys.argv parameter is a list of arguments from a command line.
|
1 |
App = QApplication(sys.argv) |
Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. also we have created the object of window and we have added 30, because we want 30 buttons.
|
1 2 |
window = Window(30) sys.exit(App.exec()) |
Run the complete code and this will be the result

Complete source code for PyQt5 GUI Creating QScrollArea Example
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from PyQt5 import QtGui from PyQt5.QtWidgets import QApplication, QWidget, QScrollArea, QVBoxLayout, QGroupBox, QLabel, QPushButton, QFormLayout import sys class Window(QWidget): def __init__(self, val): super().__init__() self.title = "PyQt5 Scroll Bar" self.top = 200 self.left = 500 self.width = 400 self.height = 300 self.setWindowIcon(QtGui.QIcon("icon.png")) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) formLayout =QFormLayout() groupBox = QGroupBox("This Is Group Box") labelLis = [] comboList = [] for i in range(val): labelLis.append(QLabel("Label")) comboList.append(QPushButton("Click Me")) formLayout.addRow(labelLis[i], comboList[i]) groupBox.setLayout(formLayout) scroll = QScrollArea() scroll.setWidget(groupBox) scroll.setWidgetResizable(True) scroll.setFixedHeight(400) layout = QVBoxLayout(self) layout.addWidget(scroll) self.show() App = QApplication(sys.argv) window = Window(30) sys.exit(App.exec()) |
Also you can check the complete video for this article