我试图用这样的wx.MessageBox
提示用户,但我面临一些问题:
response = wx.MessageBox(MESSAGE, document, wx.YES_NO | wx.STAY_ON_TOP) # prompt the user
由于某种原因,无论我传递的标志如何,对话框都拒绝保持在最佳位置。是否有一种在所有正在运行的前台应用程序顶部生成对话框的万无一失的方法?
答案 0 :(得分:-1)
我在某个地方读到wx.STAY_ON_TOP
与dialog
一起使用时只适用于MSW。尽管如此,您可以通过将STAY_ON_TOP
分配给self
编辑:
请尝试以下方法,而不是将其解除并将其标记为无效。只有点击Question
按钮保持在最顶层,其余按钮正常运行(无论如何在Linux上)
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
hbox = wx.BoxSizer()
sizer = wx.GridSizer(2, 2, 2, 2)
btn1 = wx.Button(panel, label='Info')
btn2 = wx.Button(panel, label='Error')
btn3 = wx.Button(panel, label='Question')
btn4 = wx.Button(panel, label='Alert')
sizer.AddMany([btn1, btn2, btn3, btn4])
hbox.Add(sizer, 0, wx.ALL, 15)
panel.SetSizer(hbox)
btn1.Bind(wx.EVT_BUTTON, self.ShowMessage1)
btn2.Bind(wx.EVT_BUTTON, self.ShowMessage2)
btn3.Bind(wx.EVT_BUTTON, self.ShowMessage3)
btn4.Bind(wx.EVT_BUTTON, self.ShowMessage4)
self.SetSize((300, 200))
self.SetTitle('Messages')
self.Centre()
self.Show(True)
# self.SetWindowStyle(wx.STAY_ON_TOP)
def ShowMessage1(self, event):
dial = wx.MessageDialog(None, 'Download completed', 'Info', wx.OK)
dial.ShowModal()
def ShowMessage2(self, event):
dial = wx.MessageDialog(None, 'Error loading file', 'Error',
wx.OK | wx.ICON_ERROR | wx.STAY_ON_TOP)
dial.ShowModal()
def ShowMessage3(self, event):
self.SetWindowStyle(wx.STAY_ON_TOP)
dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',
wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
dial.ShowModal()
self.SetWindowStyle(wx.DEFAULT_FRAME_STYLE)
def ShowMessage4(self, event):
dial = wx.MessageDialog(None, 'Unallowed operation', 'Exclamation',
wx.OK | wx.ICON_EXCLAMATION)
dial.ShowModal()
def main():
ex = wx.App()
Example(None)
ex.MainLoop()
if __name__ == '__main__':
main()