pythondearpygui

DearPyGui: Main window always on top


With dearpygui, I would like to have the main window (the one that contains all the other windows) to always be on top, even if it does not have focus. Here is what I have so far :

from dearpygui.core import *
from dearpygui.simple import *


with window('MainWindow', width=500, height=500):
    add_button('Read screen')

Solution

  • I went with this solution for now. I'll edit my answer if it gets supported by the library. This is a feature in their roadmap for now (see this issue).

    from multiprocessing import Process
    from time import sleep
    
    import win32con
    import win32gui
    from dearpygui.core import *
    from dearpygui.simple import *
    
    
    with window('MainWindow', width=500, height=500):
        add_button('Read screen')
    
    
    if __name__ == '__main__':
        # you have to make a new process for this in order to be able
        # to call win32gui.FindWindow on your displayed window
        p = Process(target=start_dearpygui) 
        p.start()
    
        # sleep for a while to let your window get displayed
        sleep(4)
    
        hwnd = win32gui.FindWindow('DearPyGui', None)
        win32gui.SetWindowPos(hwnd, win32con.HWND_TOPMOST, 100, 100, 300, 200, 0)