python - 是否有可能创建一个位于所有其他窗口之上的消息对话框?
问题描述
我正在尝试为我的班级管理软件创建一个 GUI。我需要一条消息,该消息会弹出给老师并询问他是否要停止操作。由于该消息必须出现在所有其他窗口的顶部
我尝试使用以下标志创建 wx.message_dialog:style = wx.STAY_ON_TOP 但它不起作用
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
解决方案
It should work, as you have coded it, unless you are on a 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)
If you are still having trouble, try setting the window style to STAY_ON_TOP as well.
#!/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()
推荐阅读
- pdf - 将eps图像转换为pdf时如何避免灰色轮廓伪影?
- css - 为什么 flex-direction 不能按照我设置的方式工作?反应js
- django - Django:如何将 null 视为等于唯一性约束的所有内容?
- javascript - 如何在我的网站上添加收藏选项?
- python - GEKKO 背包优化无法达到正确的结果
- apache - .htaccess - if 语句:主机包含(不等于)子域
- reactjs - 带有 SPA 的 Laravel Sanctum 无法正确处理注销。我似乎没有保持注销状态。我错过了什么?
- ssl - 包含 SSL 密钥和证书后的 Jupyterhub 代理错误
- spring - 反应式数据库未使用 application/stream+json 获取最新记录
- ruby - 为什么“bundle exec fastlane android”也在 ios 平台块内执行代码?