Can't select multiple files using FileDialog

Using the code:

 with wx.FileDialog(self, "Select PDF files to add", self.dirname, "*.PDF", "PDF files (*.pdf)|*.pdf", wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_FILE_MUST_EXIST) as dlg:
        dlg.SetWindowStyle(wx.STAY_ON_TOP)
        if dlg.ShowModal() != wx.ID_OK:
            return
        test=dlg.GetFilenames()

The dialog opens and works except that I am unable to select more than one file. (I also tried it using the keyword format “style=…” etc., with the same result.) What am I doing wrong?

Running under PyCharm on W10. Everything (Windows, Pycharm, packages) is up-to-date.

Your code is assigning "*.PDF" to the defaultFile parameter. I don’t think it makes sense to assign a wildcard here.

The following works on my linux PC:

        with wx.FileDialog(self,
                           "Select PDF files to add",
                           self.dirname,
                           wildcard="PDF files (*.pdf)|*.pdf",
                           style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_FILE_MUST_EXIST) as dlg:

I still see the same behavior: I can select one file only. (But I’ll switch back to using keywords.)

Are you holding down Shift or Ctrl when selecting the files?

Applying the time-honored software development technique of “changing things to see what happens” I have discovered that removing the line “dlg.SetWindowStyle(wx.STAY_ON_TOP)” fixes it. Apparently SetWindowStyle overwrites previous styles.

(Which is pretty obvious now that I think about it!)

Many thanks for your help.