wxPython公司wx.FileDialog加载需要时间

2024-09-29 23:30:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用wxPython构建一个应用程序,我需要向用户请求一个文件。以下是我的职能:

def choose_path(self, event):
    """Choose the path"""
    self.btnPath.Disable()
    path, exists = open_file()
    self.btnPath.Enable()
    if path is not None:
        if exists:
            self.txtPath.SetLabel(path)

    self.btnOpen.Enable(bool(self.txtPath.GetValue()))


def open_file(default_path="data\\pcap"):
    """Method for opening files,returns the file_path of the choosen file and exists"""

    file_path = None
    dialog = wx.FileDialog(None, "File Browser", default_path,
                           style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.STAY_ON_TOP, wildcard=OPEN_WILDCARD)

    if dialog.ShowModal() == wx.ID_OK:
        file_path = dialog.GetPath()

    dialog.Destroy()

    return file_path, os.path.exists(file_path)

问题是有时加载FileDialog需要时间,应用程序会崩溃。我能做些什么?在


Tags: thepathselfnone应用程序ifenabledef

热门问题