# Always on top Python script in MacOS

**URL:** <https://discuss.python.org/t/always-on-top-python-script-in-macos/39081>\
**Category:** Python Help\
**Created:** [November 18, 2023, 11:44pm UTC](https://discuss.python.org/t/always-on-top-python-script-in-macos/39081 "2023-11-18T23:44:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Archie](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@Archie](https://discuss.python.org/u/Archie)\
**Post date:** [November 18, 2023, 11:44pm UTC](https://discuss.python.org/t/always-on-top-python-script-in-macos/39081/1 "2023-11-18T23:44:39Z")

</div>

Dear smartest friends,  
I have python script, it showing gif in window and brings this window to top over all other opened windows (or the windows which will be opened in future). It works perfectly in Windows operation system, but in MacOS if I’m watching video in full screen or have some application in full screen when this script runs, the video is exiting from full screen and the window also exiting from full screen. And I see 2 windows next to each other, but I want one on top of the other. If the other windows not in full mode it’s OK, the problem only with full mode. Here is the very simple Python script:

```auto
import sys
import os
import subprocess
import time
from PyQt6 import QtWidgets, QtGui, QtCore

class LoadingGif(QtWidgets.QWidget):
    def __init__ (self):
        super(). __init__ ()
        
        self.setGeometry(0, 0, 200, 200)
        base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath( __file__ )))
        imagePath = os.path.join(base_path, "earth.gif")

        self.movie = QtGui.QMovie(imagePath)
        self.movie.setScaledSize(QtCore.QSize(200, 200))

        self.label = QtWidgets.QLabel(self)
        self.label.setGeometry(QtCore.QRect(0, 0, 200, 200))
        self.label.setMovie(self.movie)
        self.label.mousePressEvent = self.CloseWindow
        self.movie.start()
        
        self.setWindowFlag(QtCore.Qt.WindowType.WindowStaysOnTopHint)

    def CloseWindow(self, event):
        sys.exit()

if __name__ == " __main__":
    app = QtWidgets.QApplication(sys.argv)

    window = LoadingGif()
    window.show()
    sys.exit(app.exec())

```

I’ve tried to add some WindowFlag attributes, but I didn’t found the right one.

I’ll be very appreciated for any help or hint!

---

<div class="post-metadata">

**Author:** ![kyle](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/kyle/32/15361_2.png) [@kyle](https://discuss.python.org/u/kyle)\
**Post date:** [November 20, 2023, 6:25pm UTC](https://discuss.python.org/t/always-on-top-python-script-in-macos/39081/2 "2023-11-20T18:25:41Z")

</div>

Hey Arthur I think this should boil down to how Mac handles app launching esp, when opening full screen. launching and resizing of different windows in Windows env is much more fluid.

```auto
self.setWindowFlag(QtCore.Qt.WindowType.WindowStaysOnTopHint)

```

if you could find a way around this flag… maybe flag off or deactivate any existing windos then activate your intended window to take precedence… just a thought
