Python 从MS windows任务栏隐藏窗口
我使用pyGtk创建了一个没有装饰的窗口。该窗口从任务栏和所有窗口的顶部隐藏。在linux上,它可以正常工作,但在MS Windows窗口上,它有时隐藏在其他窗口下,并且在Windows中的任务栏上始终有“python.exe” 代表我的问题的图像: 如何从任务栏隐藏此“python.exe”窗口 我的代码:Python 从MS windows任务栏隐藏窗口,python,windows,winapi,pygtk,win32gui,Python,Windows,Winapi,Pygtk,Win32gui,我使用pyGtk创建了一个没有装饰的窗口。该窗口从任务栏和所有窗口的顶部隐藏。在linux上,它可以正常工作,但在MS Windows窗口上,它有时隐藏在其他窗口下,并且在Windows中的任务栏上始终有“python.exe” 代表我的问题的图像: 如何从任务栏隐藏此“python.exe”窗口 我的代码: class Infowindow(gtk.Window): ''' Klasa okienka informacyjnego ''' def __init__(self, json, i
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()
从任务栏中删除窗口有两个选项:
我不知道这些在PyGtk下是如何实现的。我刚刚给了你Win32的答案 再次感谢大卫·赫弗南。工作完美 适用于需要python完整解决方案的用户
- 用一种独特的方式命名您的窗口,例如:“alamakota”
- 使用查找窗口(“alamakota”)
- 对于给定的处理程序,使用隐藏任务栏(处理程序)
- 最后一次使用集合(处理程序)
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")
另一个答案中提供的Win32解决方案不是很容易,而且它与GtkWindow::show方法不兼容。Gtk3中的一个简单解决方案是:
win->set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_UTILITY); //This works
win->set_skip_taskbar_hint(); //This does not guarantee to work
如果没有更多的答案,我将尝试在Win32 GUI下创建此窗口。谢谢。
hide\u from\u任务栏
在Win7 x64上似乎不起作用。MSDN表示应改用SetWindowLongPtrW
。使用SetWindowLongPtrW
设置SW_HIDE
时,它会从任务栏中隐藏,但会再次在任务栏中显示SW_SHOW
!我可以让它工作。是我的打字错误。感谢您提供详细的代码。我在pywinauto
库中实现了类似的hide\u from_task
。