如何動態地修改有關wx.FileDropTarget窗口的標題,如何動態地修改窗口的標題約wx.FileDropTarget
也就是說,當拖放文件到窗口,窗口的標題是改變。
我知道SetTitle(os.path.basename(name)
可以修改標題,但是我不知道代碼應該放在哪裏。
幫幫我,謝謝
代碼:
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()
想知道你是否意識到我在這之前一個小時發佈了答案? – pedram