开发者

wxpython's SetTransparent doesn't capture user input if set to an opacity of zero

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()
开发者_StackOverflow

Or is there a way of giving the window no background at all rather than a completely transparent coloured background?


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.

import wx

class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
    def OnEraseBackground(self, event):
        pass # do nothing
    def OnLeftDown(self, event):
        print event.GetPosition()
    def OnKeyDown(self, event):
        if event.GetKeyCode() == wx.WXK_ESCAPE:
            self.Close()
        else:
            event.Skip()

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Frame()
    frame.ShowFullScreen(True)
    app.MainLoop()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜