To do that, use wx.FD_OPEN
without the wx.FD_FILE_MUST_EXIST
flag. This lets the dialog pick a file without attempting to open it or check its accessibility:
import wx
if __name__ == '__main__':
app = wx.App(redirect=False)
frame = wx.Frame(None)
frame.Hide() # You don't need to show the frame
dlg = wx.FileDialog(
parent=frame,
message="Select a TIA Portal project file",
wildcard="TIA Project (*.ap*)|*.ap*|All files (*.*)|*.*",
style=wx.FD_OPEN # Removed wx.FD_FILE_MUST_EXIST
)
if dlg.ShowModal() == wx.ID_OK:
selected_path = dlg.GetPath()
print("Selected file:", selected_path)
dlg.Destroy()
frame.Destroy()
app.MainLoop()