我想用 Show()打开一个无模式的对话框。打开后,我可以单击父窗口,以便对话框成功打开无模式。我遇到的问题是无模式对话框始终位于父窗口的顶部。当我点击它时,我希望父母能在上面。
我是否给对话框一个父窗口都没有关系。我测试了对话框中为 False 的 wx.STAY_ON_TOP 样式。
使用下面的简单代码(从https://www.tutorialspoint.com/wxpython/wx_dialog_class.htm复制和修改)我遇到了同样的问题。
如何获得可以在父窗口后面的无模式对话框?
import wx
# -----------------------------------------------------------------------------------
class MyDialog(wx.Dialog):
def __init__(self, parent, title):
super(MyDialog, self).__init__(parent, title=title, size=(250, 150))
panel = wx.Panel(self)
self.btn = wx.Button(panel, wx.ID_OK, label="ok", size=(50, 20), pos=(75, 50))
style = self.GetWindowStyle()
if style & wx.STAY_ON_TOP:
print('STAY_ON_TOP = True')
else:
print('STAY_ON_TOP = False')
# -----------------------------------------------------------------------------------
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title=title, size=(300, 300))
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
btn1 = wx.Button(panel, label="Modal Dialog", pos=(20, 10))
btn2 = wx.Button(panel, label="Modeless Dialog Parent", pos=(20, 40))
btn3 = wx.Button(panel, label="Modeless Dialog Parentless", pos=(20, 70))
btn1.Bind(wx.EVT_BUTTON, self.OnModal)
btn2.Bind(wx.EVT_BUTTON, self.OnModelessParent)
btn3.Bind(wx.EVT_BUTTON, self.OnModelessParentless)
self.Show(True)
def OnModal(self, event):
MyDialog(self, "Dialog").ShowModal()
def OnModelessParent(self, event):
dlg = MyDialog(self, "Dialog").Show()
def OnModelessParentless(self, event):
dlg = MyDialog(None, "Dialog").Show()
# -----------------------------------------------------------------------------------
ex = wx.App()
Mywin(None, 'Modal / Modeless')
ex.MainLoop()