前景提要
HDC调试需求开发(15万预算),能者速来!>>>
原代码如下: import wx,os class FileDrop(wx.FileDropTarget): def __init__(self, window): wx.FileDropTarget.__init__(self) self.window = window def OnDropFiles(self, x, y, filenames): for name in filenames: try: f = open(name, 'r') text = f.read() self.window.WriteText(text) f.close() except IOError, error: dlg = wx.MessageDialog(None, 'Error opening file\n' + str(error)) dlg.ShowModal() except UnicodeDecodeError, error: dlg = wx.MessageDialog(None, 'Cannot open non ascii files\n' + str(error)) dlg.ShowModal() class DropFile(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, title="", size = (450, 400)) self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE|wx.TE_RICH2) dt = FileDrop(self.text) self.text.SetDropTarget(dt) self.Centre() self.Show(True) app = wx.App() DropFile(None, -1) app.MainLoop() 我想根据拖放的文件,将文件名动态更新为窗口的标题,如:
我知道可以通过 SetTitle(os.path.basename(name)) 来设置窗口标题,但我不知道如何在类中调用或使用?求指点!谢谢!