如果将不透明度设置为零,wxpython 的 SetTransparent 不会捕获用户输入
我正在尝试制作一个 wxpython 窗口(只是一个窗口,因为它是一个窗口对象)..它填充整个屏幕并且完全不可见。然后我想允许用户在“窗口”(即屏幕上的任何位置)内单击并拖动。
当我尝试执行 self.SetTransparent(0)
时,窗口不会捕获用户输入。
这是有意的行为吗?
这是实现我想要的目标的正确方法吗?不透明度为 1
显然人眼无法区分,但我仍然很好奇为什么不能使其完全透明。
这是片段:
import wx
class Frame(wx.Frame):
def __init__(self):
style = (wx.STAY_ON_TOP | wx.NO_BORDER)
wx.Frame.__init__(self, None, title="Invisible", style=style)
self.SetTransparent(0) # This doesn't work
#self.SetTransparent(1) # But this works fine
self.Bind(wx.EVT_KEY_UP, self.OnKeyPress)
def OnKeyPress(self, event):
"""quit if user press q or Esc"""
if event.GetKeyCode() == 27 or event.GetKeyCode() == ord('Q'): #27 is Esc
self.Close(force=True)
else:
event.Skip()
app = wx.App()
frm = Frame()
frm.ShowFullScreen(True)
app.MainLoop()
或者有没有办法让窗口根本没有背景,而不是完全透明的彩色背景?
I'm trying to make a wxpython window (only a window in the sense that it's a window object).. that fills the entire screen and is completely invisible. I then want to allow the user to click and drag within the "window" (ie. anywhere on the screen).
When I try doing self.SetTransparent(0)
user input doesn't get captured by the window.
Is this intended behaviour?
Is this the correct way to achieve what I want? An opacity of 1
is obviously indistinguishable to the human eye, but I'm still curious as to why I can't make it completely transparent.
Here's the snippet:
import wx
class Frame(wx.Frame):
def __init__(self):
style = (wx.STAY_ON_TOP | wx.NO_BORDER)
wx.Frame.__init__(self, None, title="Invisible", style=style)
self.SetTransparent(0) # This doesn't work
#self.SetTransparent(1) # But this works fine
self.Bind(wx.EVT_KEY_UP, self.OnKeyPress)
def OnKeyPress(self, event):
"""quit if user press q or Esc"""
if event.GetKeyCode() == 27 or event.GetKeyCode() == ord('Q'): #27 is Esc
self.Close(force=True)
else:
event.Skip()
app = wx.App()
frm = Frame()
frm.ShowFullScreen(True)
app.MainLoop()
Or is there a way of giving the window no background at all rather than a completely transparent coloured background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以覆盖
EVT_ERASE_BACKGROUND
来实现相同的效果。我还清理了代码的其他方面。
XP 与 7 上的行为略有不同,但对于您所描述的应用程序类型来说可能不是问题。
You can override
EVT_ERASE_BACKGROUND
to accomplish the same effect.I also cleaned up other aspects of the code.
Behaves slightly differently on XP versus 7, but probably not an issue for the type of app you're describing.