【问题标题】:How to Open filename from wx txtctrl如何从 wx textctrl 打开文件名
【发布时间】:2014-11-21 06:19:51
【问题描述】:

我有一个代码可以打开一个 word 文档并将照片插入其中。 GUI 部分被证明是非常棘手的。我想要它,这样您就可以拖放文档,然后点击确定,我正在运行的代码将运行并使用从拖放功能获得的文件名...

我已经使用了这个线程的代码:

Wxpython browse for or drag and drop folder

特别是这部分:

class MyFrame(wx.Frame):
def __init__(self, parent,id):
    wx.Frame.__init__(self,parent,id,'report maker', size=(300,200))
    dt1 = MyFileDropTarget(self)
    self.tc_files = wx.TextCtrl(self, wx.ID_ANY)
    self.tc_files.SetDropTarget(dt1)


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

基本上我已经拖放了一个word doc(使用win32)并想从程序的另一个地方打开它。我不确定如何打开拖放的文件。我已经尝试了很多类似的事情......

    doc = word.Documents.Open(notify(tc_files, files[0])

提前感谢您的任何提示!

【问题讨论】:

    标签: user-interface drag-and-drop wxpython wxwidgets


    【解决方案1】:

    放置后,您应该已保存文件名或能够从放置它们的小部件中获取它们。大多数 wxPython 小部件都有一个 getter(如 GetValue、GetSelection),您可以调用它来从小部件中获取一个或多个项目。只需使用它并将该信息传递到您用于打开文档的代码的另一部分。

    【讨论】:

      猜你喜欢
      • 2011-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 2012-12-03
      相关资源
      最近更新 更多