這裏下面的代碼:wxPython的保存文件對話框給出了一個GTK警告
#!/usr/bin/env python
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,
"File and Folder Dialogs Tutorial")
panel = wx.Panel(self, wx.ID_ANY)
saveFileDlgBtn = wx.Button(panel, label="Show SAVE FileDialog")
saveFileDlgBtn.Bind(wx.EVT_BUTTON, self.onSaveFile)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(saveFileDlgBtn, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)
def onSaveFile(self, event):
"""
Create and show the Save FileDialog
"""
dlg = wx.FileDialog(
self, message="Save file as ...",
defaultDir=".",
defaultFile="", wildcard="*.*", style=wx.SAVE
)
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
print path
fp = open(path, 'w')
fp.write("bau bau")
fp.close()
dlg.Destroy()
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
給我的終端上出現以下消息時,我嘗試通過文件對話框給人一種新名稱的test.txt保存文件小工具:
(python:16795): Gtk-WARNING **: Unable to retrieve the file info for `file:///home/roberto/python/test.txt': Error stating file '/home/roberto/python/test.txt': No such file or directory
儘管這樣的消息,該文件被正確保存,但我想明白爲什麼會出現消息,以及如何避免它。這是依賴於我的系統中安裝的gtk庫嗎?我正在使用gtk版本2.24和python-wxgtk2.8進行debian測試。
非常感謝。
羅伯託
Doc建議wx.FD_SAVE不是wx.SAVE。 http://www.wxpython.org/docs/api/wx.FileDialog-class.html – AndrewStone
感謝您的改進,儘管這不會影響gtk警告。河 – robelix