GUI文本编辑器上的关闭(红色'x')未退出

时间:2013-11-08 21:21:13

标签: python user-interface

我正在努力学习构建基本的GUI,我已经开始使用简单的文本编辑器。到目前为止,我已经能够很好地完成任务,但我遇到了一个奇怪的问题。当我进行构建时,我可以单击窗口的红色“X”退出按钮(右上角)并更改一些内容并重新启动它。但是在定义了一些函数之后它似乎停止了工作,编辑器启动很好并且使用了我到目前为止使用的菜单部分,但是它不会让我“X”出来。我必须重新启动内核以使其关闭,这会让人烦恼。我试过看了它,但我没有改变任何我知道的应该导致这个。所以我想我会把它带给专家并获得意见/经验。

#!/user/bin/env python
import os
import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(500, 300))
        self.control=wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.CreateStatusBar()

        filemenu=wx.Menu()

        About_Menu=filemenu.Append(wx.ID_ABOUT, '&About','Info about')

        Exit_Menu=filemenu.Append(wx.ID_EXIT,'E&xit','Term')

        Open_Menu=filemenu.Append(wx.ID_OPEN,'&Open','Open File')

        menuBar=wx.MenuBar()
        menuBar.Append(filemenu,'&File')
        self.SetMenuBar(menuBar)

        self.Bind(wx.EVT_MENU, self.OnAbout, About_Menu)
        self.Bind(wx.EVT_MENU, self.OnExit, Exit_Menu)
        self.Bind(wx.EVT_MENU, self.OnOpen, Open_Menu)

        self.Show(True)

    def OnAbout(self,e):
        dlg=wx.MessageDialog( self, 'The Editor', 'About the Editor', wx.OK)
        dlg.ShowModal()
        dlg.Destroy()

    def OnExit(self,e):
        dlg=wx.MessageDialog( self, 'Test Exit','Exit',  wx.OK)
        dlg.ShowModal()
        dlg.Destroy()

    def OnOpen(self,e):
        self.dirname=''
        dlg=wx.FileDialog(self, 'Choose a file', self.dirname, '','*.*', wx.OPEN)

        if dlg.ShowModal()==wx.ID_OK:
            self.filename=dlg.GetFilename()
            self.dirname=dlg.GetDirectory()
            f=open(os.path.join(self.dirname, self.filename), 'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()

app=wx.App(False)
frame=MainWindow(None, 'Sample')
app.MainLoop

This is what i have to restart to get it closed

0 个答案:

没有答案
相关问题