关于wx.FileDropTarget如何动态修改窗口标题,</p>
也就是说,当将文件拖放到窗口中时,窗口的标题会改变。
我知道SetTitle(os.path.basename(name)
可以修改标题,但我不知道代码应该放在哪里。
帮帮我,谢谢!</p>
代码是:
import wx
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:
file = open(name, 'r')
text = file.read()
self.window.WriteText(text)
file.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, size = (450, 400))
self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
dt = FileDrop(self.text)
self.text.SetDropTarget(dt)
self.Centre()
self.Show(True)
app = wx.App()
DropFile(None, -1)
app.MainLoop()