Pygame 在不改变其位置的情况下将窗口设置在顶部 [英] Pygame set window on top without changing it's position
问题描述
正如我在以下主题中发现的:如何使python窗口运行为始终在顶部"?
As I found in the following topic : How to make python window run as "Always On Top"?
我知道如何在顶部放置一个窗口.但我想把它保持在同一个位置.作者说他找到了一个解决方法来找到 x 和 y 值.我想知道我如何才能做到这一点!
I know how to put a window on top. But I would like to keep it at the same position. The autor says that he found a work around to find the x and y values. I would like to know how I can achieve that !
如何获取 pygame 窗口的 x、y 值?也许这是一种错误的做法.
How can I get the x, y values of a pygame window ? Maybe it's a wrong way of doing.
我正在寻找的效果是,当我通过一些函数调用触发它时,窗口会出现在顶部.
The effect I am looking for is that the window goes on top when I trigger it with some function call.
对于那些了解英雄联盟的人来说,当游戏开始时,窗口会在顶部并保持相同的坐标.
For those who know League of legends, when a game starts, the window goes on top and remains at the same coordinates.
推荐答案
我找到了一个看起来不错的解决方案:
I found a solutions thats seems pretty well done :
#!/usr/bin/python
# -*- coding: utf-8 -*-
from ctypes import windll, Structure, c_long, byref #windows only
class RECT(Structure):
_fields_ = [
('left', c_long),
('top', c_long),
('right', c_long),
('bottom', c_long),
]
def width(self): return self.right - self.left
def height(self): return self.bottom - self.top
def onTop(window):
SetWindowPos = windll.user32.SetWindowPos
GetWindowRect = windll.user32.GetWindowRect
rc = RECT()
GetWindowRect(window, byref(rc))
SetWindowPos(window, -1, rc.left, rc.top, 0, 0, 0x0001)
现在要在顶部放置一个窗口,只需调用 onTop(pygame.display.get_wm_info()['window']) 来处理您的 pygame 窗口.
Now to put a window on top, simply call onTop(pygame.display.get_wm_info()['window']) to handle your pygame window.
这篇关于Pygame 在不改变其位置的情况下将窗口设置在顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!