Is it possible to launch another application from within a wxPython app? For example if I have a list of pdf files can the user double click on 1 of them to have the users registered pdf file application to open up and display the contents?
Asked
Active
Viewed 323 times
2
-
1see https://stackoverflow.com/questions/434597/open-document-with-default-application-in-python – Prieur Julien Jan 23 '19 at 21:03
-
Thanks for that. Can I ask a follow up. The wxpython lists a UI for filepicker but it's not showing up on glide designer – mobcdi Jan 23 '19 at 21:08
2 Answers
2
I would recommend using Python's os
module can just call os.startfile(path)
. You could also use the subprocess
module for this too.
For your second question about a file picker, see probably want wx.FileDialog
which you can read more about here:

Mike Driscoll
- 32,629
- 8
- 45
- 88
-
It is wx.FileDialog but I'm not clear how I get it as an option in wxGlade to use – mobcdi Jan 23 '19 at 21:51
1
wx.LaunchDefaultBrowser(url, flags=0)
is the feature that you are looking for.
i.e.
import wx
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=-1)
sizer = wx.BoxSizer(wx.VERTICAL)
btn = wx.Button(self, wx.NewId(), "Open PDF File",size=(20,50))
self.Bind(wx.EVT_BUTTON, self.OnOpenButton, btn)
sizer.Add(btn, 0, flag=wx.EXPAND|wx.ALL)
self.SetSizer(sizer)
def OnOpenButton(self, event):
dlg = wx.FileDialog(self, wildcard="*.pdf")
if dlg.ShowModal() == wx.ID_OK:
url = dlg.GetPath()
dlg.Destroy()
try:
if not url:
return
except:
return
wx.LaunchDefaultBrowser(url)
app = wx.App()
frame = wx.Frame(None, -1, "PDF Default Browser", size = (640, 480))
MyPanel(frame)
frame.Show(True)
app.MainLoop()

Rolf of Saxony
- 21,661
- 5
- 39
- 60