2013-07-13 87 views
0

我目前有一個使用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() 

回答

0

你不能做到這一點,你正在做的方式。您正在使用模態對話框,在對話框運行時暫停主應用程序。因此你不能與主應用程序進行交互。這意味着您不能將對話框中的路徑拖放到框架。你可以只顯示()該對話框,或者你可以看看也有一個例子的wxPython演示。