我试图找出在应用程序中使用FileDialog时可能导致崩溃的原因。
我尝试了pdb跟踪以查看发生了什么,但是它停止在“如果dlg.ShowModal()== wx.ID_OK:”,然后冻结。
class databaseOpenWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Choose Database", size=(300,300))
self.SetBackgroundColour((0,0,0))
try:
ico = wx.Icon('icon.ico', wx.BITMAP_TYPE_ICO)
self.SetIcon(ico)
except:
pass
self.dir = os.getcwd()
col = wx.BoxSizer(wx.VERTICAL)
col.AddStretchSpacer()
open = wx.Button(self, wx.ID_ANY, label="Open Database")
self.Bind(wx.EVT_BUTTON, self.getDBPath, open)
col.Add(open,0,wx.CENTER,10)
col.AddStretchSpacer()
new = wx.Button(self, wx.ID_ANY, label="New Database")
self.Bind(wx.EVT_BUTTON, self.NewDB, new)
col.Add(new,0,wx.CENTER,10)
col.AddStretchSpacer()
self.SetSizer(col)
self.Layout()
self.Show()
def getDBPath(self, event):
wildcard = "Database (*.db)|*.db"
dlg = wx.FileDialog(
self, message="Choose Database To Open",
defaultDir= self.dir,
defaultFile="",
wildcard=wildcard,
style=wx.FD_OPEN | wx.FD_CHANGE_DIR
)
if dlg.ShowModal() == wx.ID_OK:
paths = dlg.GetPaths()
global session
global database
engine = create_engine('sqlite:///' + paths[0])
Base.metadata.create_all(engine)
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
database = os.path.basename(paths[0])
dlg.Destroy()
self.Destroy()
mainGUI()
elif dlg.ShowModal() == wx.ID_CANCEL:
dlg.Destroy()
第一次单击该按钮时效果很好,现在它冻结了该应用程序。我在Windows 10上使用Python 3.7