79607968

Date: 2025-05-06 04:30:23
Score: 2
Natty:
Report link

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()
Reasons:
  • RegEx Blacklisted phrase (2): TIA
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: JOnes Peter