我一直在设计一个使用wx的python程序,该程序基本上是将文件从一个目录复制到另一个目录。基本上。 问题是,当从我的主屏幕上单击“转到”时,孔洞的东西刚好就崩溃了。没有错误! 我在下面发布了代码段,希望有人可以帮助我。
代码片段一,此片段显示正在设置的窗口:
class Mywin(wx.Frame):
def __init__(self, parent, title):
global frame
global panel
frame=self;
super(Mywin, self).__init__(parent, title = title,size = (350,250))
panel = wx.Panel(self, wx.ID_ANY, style= wx.WANTS_CHARS)
self.panel=panel
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
l1 = wx.StaticText(panel, -1, "Backup source")
panel.SetBackgroundColour("black")
hbox1.Add(l1, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.t1 = wx.TextCtrl(panel)
hbox1.Add(self.t1,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox1)
browse1 = wx.Button(panel, -1, "Browse")
browse1.Bind(wx.EVT_BUTTON, self.browsebutton1)
hbox1.Add(browse1,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox1)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
l2 = wx.StaticText(panel, -1, "Backup destination")
hbox2.Add(l2, 1, wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
self.t2 = wx.TextCtrl(panel)
hbox2.Add(self.t2,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
browse2 = wx.Button(panel, -1, "Browse")
browse2.Bind(wx.EVT_BUTTON, self.browsebutton2)
hbox2.Add(browse2,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox2)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
sel=wx.CheckBox(panel, label = 'write to log file')
self.cb1 = sel
sel2=wx.CheckBox(panel, label = 'delete files found in destination that are not found in source?')
self.cb2 = sel2
hbox3.Add(sel,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
hbox3.Add(sel2,1,wx.EXPAND|wx.ALIGN_LEFT|wx.ALL,5)
vbox.Add(hbox3)
gobutton = wx.Button(panel, -1, "go!")
gobutton.Bind(wx.EVT_BUTTON, self.go)
vbox.Add(gobutton)
panel.SetSizer(vbox)
Publisher.subscribe(self.updatestuff, "update")
self.Center()
self.Show();
self.Fit()
代码段二,通过“转到”按钮:
def go(self, again):
sourcepath=os.path.realpath(self.t1.GetValue())
print 'got source'
destpath=os.path.realpath(self.t2.GetValue())
print 'got source'
if(os.path.exists(sourcepath)==False):
wx.MessageBox("Source path not valid", 'error!', wx.OK | wx.ICON_INFORMATION)
return;
if(os.path.exists(destpath)==False):
wx.MessageBox("Destination path not valid", 'error!', wx.OK | wx.ICON_INFORMATION)
return;
if(sourcepath==destpath):
wx.MessageBox("The source and destination path may not be the same.", 'error!', wx.OK | wx.ICON_INFORMATION)
return;
print 'checked source and dest valid'
self.backup(sourcepath, destpath, self.cb1.GetValue(), self.cb2.GetValue())
崩溃的代码段3:
def backup(self, source, dest, log, deletee):
print 'readying screen'
global frame
self=frame
global panel
global dolog
global dodel
global starttime
starttime=time.time()
print 'got time set crrectly'
dolog=log
print 'set logging';
self.panel.Destroy();
在wx窗口冻结[不响应]之前,它可以设置日志,然后python2.exe停止工作,并且Windows会搜索解决方案。 我试过重新安装wx python,但并没有解决。 我也尝试使用panel作为全局变量,但是产生了同样的错误。 在这个问题上的任何帮助将不胜感激,并且如果有人愿意将我的头发重新粘在上面,那也是有帮助的,因为我已经把它全部拉出来了! :) 谢谢