Python PyQT PySide QT Animated Popup Notification and Side Menu Widgets – Free Source Code

Posted by


In this tutorial, I will show you how to create animated popup notifications and a side menu in Python using the PyQT library. These widgets are very useful for displaying information to the user and navigating through different sections of an application. I will provide you with free source code so you can easily implement these widgets in your own projects.

Step 1: Setting up your environment

Before we start with the code, make sure you have Python installed on your system. You will also need to install the PyQT library. You can do this using pip by running the following command in your terminal:

pip install PyQt5

Once you have installed PyQT, you can start writing your code.

Step 2: Creating the animated popup notification

We will start by creating the animated popup notification widget. This widget will display a message to the user for a few seconds and then fade out. Here is the code for the popup notification widget:

from PyQt5.QtWidgets import QLabel, QVBoxLayout, QWidget
from PyQt5.QtCore import QPropertyAnimation, QPoint, Qt

class PopupNotification(QWidget):
    def __init__(self, message):
        super().__init__()

        self.setStyleSheet("background-color: #FF5733; color: #ffffff; padding: 10px; border-radius: 5px;")

        self.label = QLabel(message, self)
        self.label.setAlignment(Qt.AlignCenter)

        self.layout = QVBoxLayout(self)
        self.layout.addWidget(self.label)

        self.animation = QPropertyAnimation(self, b"windowOpacity")
        self.animation.setDuration(5000)
        self.animation.setStartValue(1)
        self.animation.setEndValue(0)
        self.animation.finished.connect(self.hide)

    def showEvent(self, event):
        self.animation.start()

You can use this widget by creating an instance of the PopupNotification class and adding it to your main window. Here is an example of how to use the popup notification widget:

from PyQt5.QtWidgets import QMainWindow

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.popup = PopupNotification("Hello, World!")
        self.setCentralWidget(self.popup)

Step 3: Creating the side menu widget

Next, we will create a side menu widget that will allow the user to navigate through different sections of an application. Here is the code for the side menu widget:

from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QFrame

class SideMenu(QFrame):
    def __init__(self):
        super().__init__()

        self.setStyleSheet("background-color: #333333;")

        self.layout = QVBoxLayout(self)

        self.button1 = QPushButton("Section 1")
        self.button1.setStyleSheet("background-color: #555555; color: #ffffff;")
        self.layout.addWidget(self.button1)

        self.button2 = QPushButton("Section 2")
        self.button2.setStyleSheet("background-color: #555555; color: #ffffff;")
        self.layout.addWidget(self.button2)

        self.button3 = QPushButton("Section 3")
        self.button3.setStyleSheet("background-color: #555555; color: #ffffff;")
        self.layout.addWidget(self.button3)

You can use this widget by creating an instance of the SideMenu class and adding it to your main window. Here is an example of how to use the side menu widget:

from PyQt5.QtWidgets import QMainWindow, QHBoxLayout

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.side_menu = SideMenu()
        self.setCentralWidget(self.side_menu)

Step 4: Putting it all together

Now that we have created both the animated popup notification and side menu widgets, we can put them together in a main window. Here is an example of how to create a main window with both widgets:

from PyQt5.QtWidgets import QMainWindow, QHBoxLayout

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.side_menu = SideMenu()
        self.popup = PopupNotification("Hello, World!")

        layout = QHBoxLayout()
        layout.addWidget(self.side_menu)
        layout.addWidget(self.popup)

        widget = QWidget()
        widget.setLayout(layout)

        self.setCentralWidget(widget)

And that’s it! You now have a main window with an animated popup notification and a side menu. You can further customize these widgets by adding more buttons to the side menu or changing the style of the popup notification. Feel free to experiment with the code and make it your own.

I hope you found this tutorial helpful in creating animated popup notifications and side menus in Python using the PyQT library. Good luck with your projects!

0 0 votes
Article Rating
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@walidmat8972
1 month ago

link to source code not working , please check it

@basmaben3issa362
1 month ago

beutiful work , source code please!

@maumau4369
1 month ago

Oh your Account is suspended so we can’t see the source 🥲

@vladimirkraus1438
1 month ago

beautiful UI

@samoconnor3633
1 month ago

Have you had a look at my GUI?

@Indra-qk4bd
1 month ago

Where do you get the icon ? I am struggling to find.

@SpinnTV
1 month ago

Subscribe for more upcoming tutorials.
Download the Source code:

https://www.spinntv.com/designs/2d9bnoS2#

https://www.patreon.com/posts/55414041