Pyqt5: add loading gift while function is running

Hi all, I’m writing a pyqt project and I have a single class for main windows:

class Ui(QMainWindow):
    def __init__(self):
        uic.loadUi('./ui/smipack40.ui', self)
    def function1():

app = QApplication([])
window = Ui()

I would like create a dialog screen with a gif which runs while function1 is loading (writing files etc)
and maybe animate a gif file in the main windows (maybe in a angle of the screen or in the right side of the button which run the function1 when clicked) during function1 is running.

this is possible?

Yes, you would use QMovie to load a GIF file, and perhaps use a QLabel to display it.

If function1 (which should be a method containing a self parameter) takes a long time to run, you will need to make sure that the application’s event loop keeps running. This will ensure that the user interface does not freeze. There are a few different approaches to doing this.

First, verify that you can display a GIF file in a label, and that it animates as you expect. Then, look at ways to implement function1.

thank you

I tried with the following code:

class Ui(QMainWindow):
    def __init__(self):
        uic.loadUi('./ui/logo.ui', self)
        self.loadVideo.setText('') = QMovie(self)"./ui/loadingVideo.gif")
    def startAnimation(self):

    def stopAnimation(self):
    def onConnectionClicked(self):
        while true:

the windows opens but when I click button the movie not starts

Do you have any idea?
many thanks

I am guessing that the onConnectionClicked method is called when the button is clicked. It may be useful for you to verify that.

To begin with, remove the loop from the onConnectionClicked method and verify that the animation starts.