0

我用 wxGlade 开发了一个 GUI,它仍然可以工作。但是要启动 GUI - 我编写了一个带有一些选项的脚本。所以一切正常,但是当我按下带有“x”的红色按钮关闭窗口时 - 应用程序不会停止。

我做了一个方法,由一个单独的退出按钮调用,它在我的脚本中调用一个退出函数。但通常用户使用关闭按钮(带有 X 的红色按钮),所以我的方法没有被用来关闭窗口并且窗口最终不会关闭。

这是退出功能。

def stopExport(self, event):                      # wxGlade: MyFrame.<event_handler>
    self.Close()  # close the Frame
    from ExportManager import Exportmanager       # import the exit function
    Exportmanager().exit()                        # call it

如何使用带有“ x”的红色按钮使用此功能?

4

1 回答 1

1

根据我对您的问题的理解,当您单击关闭按钮时,您的应用程序没有关闭(右上角带有 X 的红色按钮。)

默认情况下,当您单击关闭按钮时,您的应用程序应该关闭。在您的情况下,在我看来,您已将其绑定EVT_CLOSE到某个方法,其中没有用于关闭应用程序窗口的代码。例如。考虑下面的代码片段,我有意将EVT_CLOSE事件绑定到名为closeWindow(). 这个方法什么也没做,这就是我在pass那里有关键字的原因。现在,如果您执行下面的代码片段,您可以看到应用程序窗口不会关闭。

代码

import wx
class GUI(wx.Frame):
    def __init__(self, parent, id, title):
        screenWidth = 500
        screenHeight = 400
        screenSize = (screenWidth,screenHeight)
        wx.Frame.__init__(self, None, id, title, size=screenSize)
        self.Bind(wx.EVT_CLOSE, self.closeWindow)  #Bind the EVT_CLOSE event to closeWindow()

    def closeWindow(self, event):
        pass #This won't let the app to close

if __name__=='__main__':
    app = wx.App(False)
    frame = GUI(parent=None, id=-1, title="Problem Demo-PSS")
    frame.Show()
    app.MainLoop()

因此,为了关闭应用程序窗口,您需要更改closeWindow(). 例如:当您单击关闭按钮时,以下代码片段将使用Destroy()关闭应用程序窗口。

import wx

class GUI(wx.Frame):
    def __init__(self, parent, id, title):
        screenWidth = 500
        screenHeight = 400
        screenSize = (screenWidth,screenHeight)
        wx.Frame.__init__(self, None, id, title, size=screenSize)
        self.Bind(wx.EVT_CLOSE, self.closeWindow)  #Bind the EVT_CLOSE event to closeWindow()

    def closeWindow(self, event):
        self.Destroy() #This will close the app window.


if __name__=='__main__':
    app = wx.App(False)
    frame = GUI(parent=None, id=-1, title="Problem Demo-PSS")
    frame.Show()
    app.MainLoop()

我希望它有用。

于 2014-05-09T11:59:54.073 回答