'Minimal wx.FileDialog example freezes program
I'm writing a new application.
I used to work with python 2.x and wxPython some years ago, now I got Python 3.7.0 and wxPythonPhoenix 4.0.4 msw (alas).
When I try to use wx.FileDialog with ShowModal, the program freezes.
I did not find any previous question about this. I used (and reduced for the MWE) code from wxWiki like this.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title, size=(400, 200))
fileMenu = wx.Menu()
openItem = fileMenu.Append(-1, "&Open...\tCtrl-O", "Open a new recipe")
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnOpen, openItem)
def OnOpen(self, event):
# otherwise ask the user what new file to open
with wx.FileDialog(self, "Open XYZ file", wildcard="XYZ files (*.xyz)|*.xyz",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return # the user changed their mind
#you'll never get here
app = wx.App()
frame = MyFrame(None, -1, "test")
frame.Show()
app.MainLoop()
I really don't get it, moreover the code actually worked for a couple of times.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
