# ====================================================== # Program 1 Open File Dialog (OFD) works nicely Program 1 # ====================================================== import wx class MyForm(wx.Frame): app = wx.App() frame = wx.Frame(None, -1, 'win.py') # frame.SetDimensions(0,0,200,50) frame.SetSize(0,0,200,50) wx.MessageBox('Ready to show the dialog', 'Open File Dialog', wx.OK | wx.ICON_INFORMATION) openFileDialog = wx.FileDialog(frame, "Open", "", "", "Text files (*.txt)|*.txt", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) openFileDialog.ShowModal() print("-------------------------------") print(openFileDialog.GetPath()) print("-------------------------------") openFileDialog.Destroy() wx.MessageBox('The dialog was shown ', 'Open File Dialog', wx.OK | wx.ICON_INFORMATION) # ====================================================== # Program 2 never shows the OFD and exits with an error message. Program 2 # ====================================================== import wx import os ######################################################################## class MyForm(wx.Frame): #---------------------------------------------------------------------- def __init__(self): wx.Frame.__init__(self, None, title="Display a Bitmap Image") self.panel = wx.Panel(self, wx.ID_ANY) frame = wx.Frame(None, -1, 'win.py') frame.SetSize(0,0,200,50) menuBar = wx.MenuBar() # Add a MenuBar fileMenu = wx.Menu() openFileMenuItem = fileMenu.Append(wx.NewId(), "Open a bmp file") # ------- create a submenu subMenu = wx.Menu() historyMenuItem = subMenu.Append(wx.NewId(), "Show History") fileMenu.Append(wx.NewId(), "History", subMenu) # fileMenu.AppendMenu(wx.NewId(), "History", subMenu) exitMenuItem = fileMenu.Append(wx.NewId(), "Exit", "Exit the application") # -------------------------------------------------------- menuBar.Append(fileMenu, "&File") self.Bind(wx.EVT_MENU, self.onExit, exitMenuItem) self.Bind(wx.EVT_MENU, self.onOpenFile,openFileMenuItem ) self.SetMenuBar(menuBar) #---------------------------------------------------------------------- def onExit(self, event): self.Close() # frame.Destroy() def onOpenFile(self, evt=None): wx.MessageBox('Ready to show the dialog', 'Open File Dialog', wx.OK | wx.ICON_INFORMATION) openFileDialog = wx.FileDialog(frame, "Open", "", "", "Text files (*.txt)|*.txt", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) wx.MessageBox('The dialog was shown ', 'Open File Dialog', wx.OK | wx.ICON_INFORMATION) openFileDialog.ShowModal() print("-------------------------------") print(openFileDialog.GetPath()) print("-------------------------------") openFileDialog.Destroy() # =================================================== # Run the program if __name__ == "__main__": # app = wx.App(False) # Original code app = wx.App(True) # app = wx.App(True) frame = MyForm().Show() app.MainLoop() # ------------------------------------------------------ Error Follows-------- Traceback (most recent call last): File "D:\Software Development\Python Assets\PythonApplications\Show Bitmap\ShowMyBitMap.py", line 65, in onOpenFile wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) TypeError: FileDialog(): argument 1 has unexpected type 'bool' # ----------------------------------------------------------------------------------- # Also # The code also generates a Red X Remote server is not connected