简体   繁体   English

在其他 windows 之上打开一个 window

[英]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.

相关问题 如何自定义(Windows OS)中的pybusyinfo窗口,使其出现在窗口的顶部和其他格式设置选项中? - How to customize pybusyinfo window in (windows OS) to make it appear at top corner of window and the other formatting options? 使一个窗口出现在另一个窗口的上方,禁止访问其他窗口,直到单击按钮 - Make a window appear on top of another, block access to other windows until button clicked 如何在Spyder中的所有其他窗口的顶部显示matplotlib图形窗口 - How do I display a matplotlib figure window on top of all other windows in Spyder 从任务栏单击时,Tkinter 使覆盖重定向窗口出现在其他窗口的顶部 - Tkinter make overrideredirect window appear on top of other windows when clicked from taskbar 在tkinter中从其他窗口打开窗口 - Opening windows from other windows in tkinter 使用python在单个窗口中打开其他应用程序 - Opening other application in single window using python Python OpenCV在其他应用程序之上打开窗口 - Python OpenCV open window on top of other applications PyGTK窗口始终位于所有“始终位于顶部”窗口中 - PyGTK Window always on top of all 'always on top` windows python 在其他 windows 顶部打开文件夹 - python open folder on top of other windows 为什么其他窗口(GUI)在 Python 中运行时其他窗口(GUI)没有打开? - Why other window(GUI) is not opening while other window(GUI) is running in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM