0

我试图让我的空框架,以便当我单击 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()
4

1 回答 1

0

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

所以(从您的链接复制的缩短示例):

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()
于 2013-08-15T14:15:54.290 回答