【问题标题】:wxpython drag and drop one folder then another to add to listwxpython 拖放一个文件夹,然后将另一个文件夹添加到列表中
【发布时间】:2014-02-15 17:07:20
【问题描述】:

我正在使用下面的代码创建一个拖放窗口,将文件夹拖放到该窗口以获取文件夹路径。我想要的是能够删除一个文件夹,然后删除另一个文件夹,该文件夹添加到列表中,然后可能另一个文件夹添加到列表中,依此类推。目前,如果我在第一个文件夹之后放置另一个文件夹,它只会在窗口中显示第一个文件夹。如何让它显示正在添加的新内容并将它们添加到列表中?

    def queue(self, event):
        self.Show()
        dt1 = MyFileDropTarget(self)
        self.tc_files = wx.TextCtrl(self.panel1, wx.ID_ANY, pos=(42, 120), size=(500, 405))
        self.tc_files.SetDropTarget(dt1)

    def notify(self, indir):
        """Update file in testcontrol after drag and drop"""
        self.tc_files.SetValue(indir[0])

class MyFileDropTarget(wx.FileDropTarget):
    """"""
    def __init__(self, window):
        wx.FileDropTarget.__init__(self)
        self.window = window

    def OnDropFiles(self, x, y, filenames):
        self.window.notify(filenames)

【问题讨论】:

  • 只需修改 notify 函数以将字符串设置为所有字符串,而不仅仅是第一个 ...

标签: python drag-and-drop wxpython


【解决方案1】:

正如@JoranBeasley 所说,您需要使用 indir 列表来设置您显示的字符串:

self.tc_files.SetValue(",".join(indir))

应该这样做。

【讨论】:

    猜你喜欢
    • 2020-02-10
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多