Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在对话类中创建wx.filedialog?_Python_Wxpython_Filedialog - Fatal编程技术网

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

Python 无法在对话类中创建wx.filedialog?,python,wxpython,filedialog,Python,Wxpython,Filedialog,我创建了一个如下所示的类。但是当我用“保存文件”按钮绑定事件时,wx.filelog不会被设置。真奇怪。所以我将超类更改为wx.Frame,然后它成功了。有人能告诉我为什么吗?谢谢 class TestDialog(wx.Dialog): def __init__( self, parent, ID, title, size=wx.DefaultSize, pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_ST

我创建了一个如下所示的类。但是当我用“保存文件”按钮绑定事件时,wx.filelog不会被设置。真奇怪。所以我将超类更改为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)      

`

使用此代码,它必须与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()

你在任何时候都在调用ShowModal()吗?是的!我忘了!谢谢,嗯!:-DDoS调用
showmodel()
解决您的问题?我不知道你所说的“不准备建立”是什么意思。我猜你的意思是对话没有显示。是的!是的。谢谢你的帮助。事实上我花了很长时间来解决这个问题,最后我发现它太愚蠢了。呵呵呵呵~再次感谢你。别担心。有时你所需要的只是第二双眼睛。