Advertisement
yclee126

wxpython drag and drop

Sep 24th, 2021 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import wx
  2.  
  3. class FileDrop(wx.FileDropTarget):
  4.  
  5. def __init__(self, window):
  6.  
  7. wx.FileDropTarget.__init__(self)
  8. self.window = window
  9.  
  10. def OnDropFiles(self, x, y, filenames):
  11.  
  12. text = '\n'.join(filenames)
  13. self.window.Clear()
  14. self.window.WriteText(text)
  15.  
  16. return True
  17.  
  18. class Example(wx.Frame):
  19.  
  20. def __init__(self, parent, id, title):
  21. wx.Frame.__init__(self, parent, id, title)
  22.  
  23. self.InitUI()
  24.  
  25. def InitUI(self):
  26.  
  27. self.text = wx.TextCtrl(self, style = wx.TE_MULTILINE)
  28. dt = FileDrop(self.text)
  29.  
  30. self.text.SetDropTarget(dt)
  31. self.SetSize((500, 200))
  32. self.Centre()
  33.  
  34.  
  35. def main():
  36.  
  37. app = wx.App()
  38. ex = Example(None, wx.ID_ANY, 'File drag and drop')
  39. ex.Show()
  40. app.MainLoop()
  41.  
  42.  
  43. if __name__ == '__main__':
  44. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement