无法在对话框类中创建wx.filedialog?

时间:2012-08-20 00:00:16

标签: python wxpython filedialog

我在下面创建了一个类。但是当我使用“保存文件”按钮绑定事件时,wx.filelog不会设置。这真的很奇怪。所以我将SuperClass改为wx.Frame,然后它成功了。任何人都可以告诉我为什么?感谢。

class TestDialog(wx.Dialog):
    def __init__(
        self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition,
        style=wx.DEFAULT_DIALOG_STYLE,
        useMetal=False,):
        self.pre = wx.PreDialog()
        self.pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP)
        self.pre.Create(parent, ID, title, pos, size, style)
        self.PostCreate(self.pre)
        self.fileButton = wx.Button(self , -1, "save file!")
        self.Bind(wx.EVT_BUTTON, self.OnCompressToFileButton, self.fileButton)
    def OnCompressToFileButton(self, event):
        wildcard = "compress file(*.cof)|*.cof|Lempel-Zivsliding window compressfile(*.lz)|*.lz"
        dlg = wx.FileDialog(self, message="Save file as ...", defaultDir=os.getcwd(),         defaultFile="", wildcard=wildcard, style=wx.SAVE)      

`

1 个答案:

答案 0 :(得分:0)

使用此鳕鱼必须与wx.Dialog一起使用

def OnCompressToFileButton(self, event):
    dlg = wx.FileDialog(self, "Choose a file",os.getcwd(), "", "*.*", wx.SAVE | wx.OVERWRITE_PROMPT)
    if dlg.ShowModal() == wx.ID_OK:
        self.filename=dlg.GetFilename()
        self.dirname=dlg.GetDirectory()