【问题标题】:Enabling the dock icon on Mac with WxPython使用 WxPython 在 Mac 上启用停靠图标
【发布时间】:2013-08-15 14:08:18
【问题描述】:

我正在尝试获取我的空框架,以便当我单击 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()

【问题讨论】:

    标签: python macos window wxpython hide


    【解决方案1】:

    您链接到的文档声明您需要在应用程序上添加这些事件处理程序。您当前已在框架上定义它们。所以你需要扩展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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2018-08-09
      • 1970-01-01
      • 2011-05-23
      • 2011-10-11
      • 2011-06-10
      • 1970-01-01
      相关资源
      最近更新 更多