有没有可能创建一个消息对话框,将停留在所有其他窗口的顶部?

2024-05-16 21:25:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为我的班级管理软件创建一个GUI。我需要一条信息,弹出给老师,问他是否想停止手术。因此,该消息必须出现在所有其他窗口的顶部

我试着创造一个wx.message\u对话框使用标志:style=wx.站在上面 但它不起作用

def stopscreen(self): 
    stopBox = wx.MessageDialog(None, "do you want to stop","stop controling", style=wx.STAY_ON_TOP | wx.YES_NO | wx.CENTRE)
    stopBoxAns = stopBox.ShowModal()
    if stopBoxAns == 5103:
        stopBox.Destroy()
        return 1### ok
    if stopBoxAns == 5104:
        stopBox.Destroy()
        return 2### cancel

Tags: 信息消息returnifstyle管理软件gui老师
1条回答
网友
1楼 · 发布于 2024-05-16 21:25:55

它应该工作,因为你已经编码它,除非你是在Mac上。你知道吗

wx.STAY_ON_TOP: Makes the message box stay on top of all other windows and not only just its parent (currently implemented only under MSW and GTK)

如果仍有问题,请尝试将“窗口样式”设置为“在顶部”。你知道吗

#!/usr/bin/env python

import wx

#                                     -

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1)
        panel = wx.Panel(self)
        self.SetWindowStyle(wx.STAY_ON_TOP)
        button = wx.Button(panel, -1, "Show MessageDialog", (50,50))
        self.Bind(wx.EVT_BUTTON, self.OnButton)
        self.Show()

    def OnButton(self, event):
        dlg = wx.MessageDialog(self, 'Hello from wxPython!',
                               'A Message Box',
                               wx.YES | wx.NO | wx.ICON_INFORMATION | wx.STAY_ON_TOP
                               )
        dlg.ShowModal()
        dlg.Destroy()


if __name__ == "__main__":
    app = wx.App(False)
    MyFrame(None)
    app.MainLoop()

相关问题 更多 >