How to open a window on top of other windows when calling a function?
import wx
def openFile(wildcard="*"):
app = wx.App(None)
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
dialog = wx.FileDialog(None, 'Open', wildcard=wildcard, style=style)
if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPath()
else:
dialog.Destroy()
path = 'No file'
return f'<div class="notification error">{path}</div>'
dialog.Destroy()
return f'<div id="pathToFile" class="notification">{path}</div>'
The Accepted answer from @VZ is spot on for all normal usage but strictly speaking, your code can be tweaked to work, even if it serves no real purpose but you'll notice, despite passing wx.STAY_ON_TOP
, it will not honour it.
Like so:
import wx
def openFile(wildcard="*"):
app = wx.App(None)
style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST | wx.STAY_ON_TOP
dialog = wx.FileDialog(None, 'Open', wildcard=wildcard, style=style)
if dialog.ShowModal() == wx.ID_OK:
path = dialog.GetPath()
else:
path = 'No file'
dialog.Destroy()
return f'<div class="notification error">{path}</div>'
print(openFile())