使用pyGtk,我创建了一个没有装饰的窗口。该窗口从任务栏和所有窗口的顶部隐藏。在Linux上,它工作正常,但在MS Windows窗口上,有时它隐藏在其他窗口下,并且在窗口中的任务栏上始终带有“ python.exe”。
代表我的问题的图像:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9ja21wdC5wbmcifQ==” alt =“在此处输入图像描述”>
如何隐藏任务栏上的“ python.exe”窗口?
我的代码:
class Infowindow(gtk.Window):
'''
Klasa okienka informacyjnego
'''
def __init__(self, json, index, destroy_cb, device):
gtk.Window.__init__(self)
self.size_x = 260+48
self.size_y = 85
self.separator_size = 10
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN)
self.set_decorated(False)
self.set_property('skip-taskbar-hint', True)
self.set_opacity(1)
self.set_keep_above(True)
self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.connect("enter-notify-event", self.__on_hover)
self.connect("leave-notify-event", self.__on_leave)
self.connect("button_press_event", self.__on_click)
self.set_size_request(self.size_x, self.size_y)
color = gtk.gdk.color_parse('#f3f3f3')
self.modify_bg(gtk.STATE_NORMAL, color)
self.expanded = False
self.index = index
self.destroy_cb = destroy_cb
self.json = json['data']
self.system_info = False if 'system' not in self.json or not self.json['system'] else True
self.device = device
f = gtk.Frame()
self.move_window(index) #move window to specified place
self.box_area = gtk.VBox()
self.box_area.set_spacing(10)
f.add(self.box_area)
self.add(f)
self.show_all()
您有两个选项可从任务栏中删除窗口:
WS_EX_TOOLWINDOW
扩展窗口样式。但这还有其他后果,我不能说它们是否很严重。您的窗口自然会在其他窗口之下。这就是Windows的工作方式。如果要使窗口显示在顶部,请显示HWND_TOPMOST
。
我不知道在PyGtk下如何实现(或不实现)这些。我刚刚给了您Win32的答案!
再次感谢David Heffernan。完美的作品!
对于想要使用python提供完整解决方案的人。
窗口从任务栏隐藏,并且始终在顶部。
我知道这不是完整的代码,但是在Windows XP及更高版本上可以正常工作。
HWND_TOPMOST
另一个答案中提供的Win32解决方案不是很容易,它不能与GtkWindow :: show方法配合使用。现在在Gtk3中一个简单的解决方案是:
import ctypes
import win32gui
import win32api
from win32con import SWP_NOMOVE
from win32con import SWP_NOSIZE
from win32con import SW_HIDE
from win32con import SW_SHOW
from win32con import HWND_TOPMOST
from win32con import GWL_EXSTYLE
from win32con import WS_EX_TOOLWINDOW
@staticmethod
def find_window(name):
try:
return win32gui.FindWindow(None, name)
except win32gui.error:
print("Error while finding the window")
return None
@staticmethod
def hide_from_taskbar(hw):
try:
win32gui.ShowWindow(hw, SW_HIDE)
win32gui.SetWindowLong(hw, GWL_EXSTYLE,win32gui.GetWindowLong(hw, GWL_EXSTYLE)| WS_EX_TOOLWINDOW);
win32gui.ShowWindow(hw, SW_SHOW);
except win32gui.error:
print("Error while hiding the window")
return None
@staticmethod
def set_topmost(hw):
try:
win32gui.SetWindowPos(hw, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE)
except win32gui.error:
print("Error while move window on top")