使用WxPython在Mac上启用停靠栏图标

时间:2013-08-15 14:08:19

标签: python macos window wxpython hide

我正在尝试获取我的空框架,以便当我单击X时它只是隐藏窗口,然后如果我按下停靠栏图标它将显示窗口。事实证明,这比我预期的更具挑战性。我使用了http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X/,但我无法做到这一点。

这是我的代码:

import wx

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "title",style=wx.SYSTEM_MENU | wx.CLOSE_BOX | wx.CAPTION, size=(300,300))
    panel = wx.Panel(self)


    def MacReopenApp(self, event):
         print "Attempting to reveal the window."

    def MacHideApp(self, event):
        print "Attempting to hide the window."


if __name__ == '__main__':
    app = wx.App()
    frame = Frame()
    frame.Show()
    app.MainLoop()

1 个答案:

答案 0 :(得分:0)

您链接的文档指出您需要在App上添加这些事件处理程序。您当前已在框架上定义它们。因此,您需要扩展wx.App并定义这些事件处理程序,并实例化您自己的App而不是wx.App

所以(从your link复制的缩写示例):

class MyApp(wx.App):
    def __init__(self, *args, **kwargs):
        wx.App.__init__(self, *args, **kwargs)

        # This catches events when the app is asked to activate by some other
        # process
        self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate)

    #.....

    def MacReopenApp(self):
        """Called when the doc icon is clicked, and ???"""
        self.BringWindowToFront()

app = MyApp(False)
app.MainLoop()