【问题标题】:Wxpython save is not working in Windows7Wxpython 保存在 Windows7 中不起作用
【发布时间】:2013-06-11 05:36:55
【问题描述】:

我需要在我的编辑器中保存一个文本文件,这是保存文件的代码,但该代码在 Windows 7 中不起作用 我的代码是

def OnSaveFile(self, event):
        if self.last_name_saved:

            try:
                file = open(self.last_name_saved, 'w')
                text = self.text.GetValue()
                file.write(text.encode('utf-8'))
                file.close()
                self.statusbar.SetStatusText(os.path.basename(self.last_name_saved) + ' saved', 0)
                self.SetTitle(os.path.basename(self.last_name_saved))
                self.modify = False
                self.statusbar.SetStatusText('', 1)

            except IOError, error:
                dlg = wx.MessageDialog(self, 'Error saving file\n' + str(error))
                dlg.ShowModal()
        else:
            self.OnSaveAsFile(event)

这是我的错误。

Traceback (most recent call last):
File "F:\EZHUTHANI_WIN\ezhuthani\beditor.py", line 301, in OnSaveFile
self.OnSaveAsFile(event)
File "F:\EZHUTHANI_WIN\ezhuthani\beditor.py", line 308, in OnSaveAsFile
if save_dlg.ShowModal() == wx.ID_OK:
File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_windows.py", line 711, in ShowModal
return _windows_.Dialog_ShowModal(*args, **kwargs)

这是程序中保存文件的模块

def OnSaveAsFile(self, event):
        wcd='All files(*)|*|Editor files (*.ef)|*.ef|'
        dir = os.getcwd()
        save_dlg = wx.FileDialog(self, message='Save file as...', defaultDir=dir, defaultFile='',
                        wildcard=wcd, style=wx.SAVE | wx.OVERWRITE_PROMPT)
        if save_dlg.ShowModal() == wx.ID_OK:
            path = save_dlg.GetPath()

            try:
                file = open(path, 'w')
                text = self.text.GetValue()
                file.write(text.encode('utf-8'))
                file.close()
                self.last_name_saved = os.path.basename(path)
                self.statusbar.SetStatusText(self.last_name_saved + ' saved', 0)
                self.modify = False
                self.statusbar.SetStatusText('', 1)
                self.SetTitle(window_title + path)
            except IOError, error:
                dlg = wx.MessageDialog(self, 'Error saving file\n' + str(error))
                dlg.ShowModal()
        save_dlg.Destroy()

【问题讨论】:

标签: python-2.7 wxpython wxwidgets


【解决方案1】:

检查 OnSaveAsFile() 函数中的通配符,

把它改成类似,

wcd='Text files(*.txt)|*.txt|Plain Text files (*.txt)|*.txt'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-31
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多