[英]Opening a window on top of other windows
How to open a window on top of other windows when calling a function?如何在调用 function 时在其他 windows 之上打开一个 window?
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>'
To show a dialog on top of some other top level window you need to specify that window as the dialog parent (instead of using None
as you do).要在其他顶级 window 之上显示一个对话框,您需要将 window 指定为对话框父级(而不是像您那样使用None
)。
There is no support for showing a native dialog, such as the "Open file" one, on top of all windows, this can only be done for custom windows using wx.STAY_ON_TOP
flag.不支持在所有 windows 之上显示原生对话框,例如“打开文件”对话框,这只能使用wx.STAY_ON_TOP
标志为自定义 windows 完成。
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. @VZ 接受的答案适用于所有正常使用,但严格来说,您的代码可以调整以工作,即使它没有真正的用途,但您会注意到,尽管通过wx.STAY_ON_TOP
,它不会兑现它。
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())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.