wx.TextCtrl使用拖放文件夹来获取文件路径

时间:2013-07-13 20:22:15

标签: python drag-and-drop wxpython wx.textctrl

我目前有一个使用wx.TextCtrl的工作应用程序,我打开一个选择文件夹对话框。我想添加拖放功能,这样我就可以拖放文件夹来获取文件夹路径,这样我就可以为用户提供这两个选项。 以下是我当前代码的一部分:

self.pathindir = wx.TextCtrl(panel, -1, pos=(35, 380), size=(300, 25))
self.buttonin = wx.Button(panel, -1, "Open", pos=(350, 378))
self.buttonin.Bind(wx.EVT_BUTTON, self.openindir)
def openindir(self, event):
    dlg = wx.DirDialog(self, "Choose your input lookup directory:", style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON)
    if dlg.ShowModal() == wx.ID_OK:
        global pathindir
        pathindir = dlg.GetPath()
        self.SetStatusText("Your selected input lookup directory is: %s" % pathindir)
    self.pathindir.Clear()
    self.pathindir.WriteText(pathindir)
    dlg.Destroy()

1 个答案:

答案 0 :(得分:0)

你无法按照自己的方式去做。您正在使用模式对话框,该对话框在对话框运行时暂停主应用程序。因此,您无法与主应用程序进行交互。这意味着您无法将对话框中的路径拖放到框架中。你可以只显示()对话框,或者你可以看看wxPython演示,它也有一个例子。