首页 > 解决方案 > DearPyGui:主窗口始终位于顶部

问题描述

使用dearpygui,我希望主窗口(包含所有其他窗口的窗口)始终位于顶部,即使它没有焦点。这是我到目前为止所拥有的:

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


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

标签: pythondearpygui

解决方案


我现在选择了这个解决方案。如果图书馆支持,我会编辑我的答案。这是他们目前路线图中的一个功能(请参阅本期)。

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)

推荐阅读